Jump to content

get current page name as displayed in URL


RLJ

Recommended Posts

Hi all,

 

I want to get the current page name as displayed in the URL, not neccesarily the name of the PHP script that is running.

 

E.g. I have a PHP file 'home.php' that contains iframes that contain other PHP files such as 'frame1.php'. What I want is a script that can be run from frame1.php but that will return 'home.php' as the current page (as displayed in the URL in the browser).

 

How do I do this?

 

Thanks!

Link to comment
Share on other sites

	function selfURL() {
	$s = empty($_SERVER["HTTPS"]) ? ''
		: ($_SERVER["HTTPS"] == "on") ? "s"
		: "";
	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
	$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
		: (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); 
}
$thisPage = (selfURL());

Link to comment
Share on other sites

Thanks for your help, but selfURL and anything I can find under $_SERVER seems to return the URL or the script name of the currently running script. So if this script is called from within an iframe, then it doesn't return the page name of the page that contains the iframe, as I want it to do.

 

Any ideas?

 

Thanks!

Link to comment
Share on other sites

$_SERVER['HTTP_REFERER'] seems to be your best bet, but it can be edited by users.

Or have a variable started on the parent page and passed to the iframe (like iframe src="page.php?parent=blah", and then using $_GET in the iframe), though this can also be edited by users, or the parent page stored in a $_SESSION variable (which can't be user edited).

 

Why are you wanting to use iframes anyway?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.