graham23s Posted September 27, 2008 Share Posted September 27, 2008 Hi Guys, i store what page the user is viewing like this: $page = $_SERVER['PHP_SELF']; which displays for example: page.php but the page is actually: page.php?productid=4 is it possible to store the bit after the .php aswell? thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/ Share on other sites More sharing options...
ratcateme Posted September 27, 2008 Share Posted September 27, 2008 you would have to loop through the get array something like this foreach($_GET as $key => $value){ if(isset($page)){ $page = "?{$key}={$value}"; }else{ $page .= "&{$key}={$value}"; } } $page = $_SERVER['PHP_SELF'].$page; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-651791 Share on other sites More sharing options...
graham23s Posted September 27, 2008 Author Share Posted September 27, 2008 ah ok thanks Scott Graham Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-651794 Share on other sites More sharing options...
wildteen88 Posted September 27, 2008 Share Posted September 27, 2008 you would have to loop through the get array something like this foreach($_GET as $key => $value){ if(isset($page)){ $page = "?{$key}={$value}"; }else{ $page .= "&{$key}={$value}"; } } $page = $_SERVER['PHP_SELF'].$page; Scott. You could just use $_SERVER['QUERY_STRING'] eg $page = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] Alternatively you could just a single var called $_SERVER['REQUEST_URI'] Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-651872 Share on other sites More sharing options...
ratcateme Posted September 27, 2008 Share Posted September 27, 2008 but if there was no query string you would get a random ? at the end of your url. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-652053 Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 but if there was no query string you would get a random ? at the end of your url. Scott. Not if you used $_SERVER['REQUEST_URI']. However you could just check to see $_SERVER['QUERY_STRING'] actually holds anything before adding it on to $page Quote Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-652291 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.