Jump to content

$_SERVER['PHP_SELF']; question


graham23s

Recommended Posts

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

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 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']

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.