cloudll Posted December 4, 2014 Share Posted December 4, 2014 I am trying to include my full url on my site. example /index.php?page=demo On my local server this bit of code worked fine. $active = "$_SERVER[REQUEST_URI]"; however on my live server it returns blank, i think maybe due to the fact that its a windows server ? php self works, but only returns index.php and not the full ?page=demo url $active = ($_SERVER['PHP_SELF']); does anyone know how i can work around this? Thanks Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/ Share on other sites More sharing options...
gizmola Posted December 4, 2014 Share Posted December 4, 2014 That is some odd behavior. If you omit the server portion in a url, your hostname will be inferred/filled in. This goes for forms that don't specify a target as well. They will post to themselves. Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/#findComment-1498547 Share on other sites More sharing options...
hansford Posted December 5, 2014 Share Posted December 5, 2014 I haven't had the "pleasure" of running into this problem because I only run on Linux. However, the question intrigued me and I did some digging and found some other people who had similar experiences. It seems that PHP running on Windows has an empty: $_SERVER[REQUEST_URI] Here is one article with a workaround. http://davidwalsh.name/iis-php-server-request_uri You can try it and see if it's something you can work with. There is a solution, maybe not this one, but there is a one out there. Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/#findComment-1498579 Share on other sites More sharing options...
QuickOldCar Posted December 5, 2014 Share Posted December 5, 2014 $current_url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER['QUERY_STRING'])) { $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $current_url .= "?" . $query_string; } Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/#findComment-1498580 Share on other sites More sharing options...
QuickOldCar Posted December 5, 2014 Share Posted December 5, 2014 I guess can improve on this with the scheme as well $_SERVER['REQUEST_SCHEME'] also has issues, so will just test for https if (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $scheme = "https"; } else { $scheme = "http"; } $current_url = filter_var($scheme."://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER['QUERY_STRING'])) { $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $current_url .= "?" . $query_string; } Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/#findComment-1498582 Share on other sites More sharing options...
requinix Posted December 5, 2014 Share Posted December 5, 2014 http://support.microsoft.com/kb/954946 Link to comment https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/#findComment-1498586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.