Cless Posted December 22, 2008 Share Posted December 22, 2008 It there a way to find out the current page URL? Well, I know you can, but... Basically, I need to be able to find the actual URL you are on. For example, if you are on "www.blah.com/pie.php", I want it to return that value. Only exception is, for example, if you are using a web proxy or something, the site is displayed in an iframe. Let's say the URL of the proxy you are using is, like ", and it is displaying "www.blah.com/pie.php" through a proxy (meaning it is showing in an iframe, usually). The actual URL is "www.blahproxy.com/blah.com/pie.php". So basically, if you viewing the page normally, it will return "www.blah.com/pie.php", elsewise, it will return "www.blahproxy.com/blah.com/pie.php". Note: I know that not all proxies use iFrames, I was just using it as an example. Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/ Share on other sites More sharing options...
JasonLewis Posted December 22, 2008 Share Posted December 22, 2008 $_SERVER['REQUEST_URI'] should return the entire URL. Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721088 Share on other sites More sharing options...
Cless Posted December 22, 2008 Author Share Posted December 22, 2008 Doesn't that just return "/index.php" or something? Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721092 Share on other sites More sharing options...
JasonLewis Posted December 22, 2008 Share Posted December 22, 2008 Try a combination, like: $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721096 Share on other sites More sharing options...
phpSensei Posted December 22, 2008 Share Posted December 22, 2008 You can use a much better script like, which always returns the correct url and its much more reliable. <?php 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)); } ?> Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721098 Share on other sites More sharing options...
Cless Posted December 22, 2008 Author Share Posted December 22, 2008 Well yeah, but it still only displays the url of the page being displayed, rather than the actual URL in the search bar. Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721103 Share on other sites More sharing options...
Cless Posted December 22, 2008 Author Share Posted December 22, 2008 Ah, wait. I found a way to do it via JavaScript (window.location), which will suffice. Thanks! Link to comment https://forums.phpfreaks.com/topic/137963-finding-out-the-current-page-url/#findComment-721107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.