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 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. 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 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'] 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. 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 Link to comment https://forums.phpfreaks.com/topic/126039-_serverphp_self-question/#findComment-652291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.