galvin Posted April 17, 2011 Share Posted April 17, 2011 If I have this code throughout my website... $_SESSION['currentpage']=$_SERVER['PHP_SELF']; I'm finding that if the URL is "mypage.php?id=1", then $_SERVER['PHP_SELF'] only returns "mypage.php" (it excludes anything appended to the end of the URL). Is that right? If so, how can I preserve the full URL (i.e. including the stuff after the question mark) Link to comment https://forums.phpfreaks.com/topic/233994-php_self-not-including-info-appended-to-url/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2011 Share Posted April 17, 2011 php apparently changed the behavior of $_SERVER['PHP_SELF'] (with out apparently telling anyone, I could find no documentation in the change log.) It used to include the URL query string, but currently does not. You should use $_SERVER['QUERY_STRING'] to get the part of the URL after the ? Link to comment https://forums.phpfreaks.com/topic/233994-php_self-not-including-info-appended-to-url/#findComment-1202700 Share on other sites More sharing options...
galvin Posted April 17, 2011 Author Share Posted April 17, 2011 Interesting. Would it be like this... $_SESSION['currentpage']=$_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']; I think I'm doing something wrong because I tried it and it's not working Link to comment https://forums.phpfreaks.com/topic/233994-php_self-not-including-info-appended-to-url/#findComment-1202703 Share on other sites More sharing options...
galvin Posted April 17, 2011 Author Share Posted April 17, 2011 Disregard, i got it working. Thanks again for the info! Link to comment https://forums.phpfreaks.com/topic/233994-php_self-not-including-info-appended-to-url/#findComment-1202715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.