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!

	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());

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!

$_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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.