RLJ Posted February 20, 2011 Share Posted February 20, 2011 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! Quote Link to comment Share on other sites More sharing options...
Hybride Posted February 20, 2011 Share Posted February 20, 2011 Take a look at Server variables, particularly Request_URI and Script_name. Quote Link to comment Share on other sites More sharing options...
DBookatay Posted February 20, 2011 Share Posted February 20, 2011 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()); Quote Link to comment Share on other sites More sharing options...
RLJ Posted February 21, 2011 Author Share Posted February 21, 2011 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! Quote Link to comment Share on other sites More sharing options...
RestlessThoughts Posted February 21, 2011 Share Posted February 21, 2011 $_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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.