php self to include full url

Associate
Joined
11 Oct 2008
Posts
268
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
 
Soldato
Joined
12 Dec 2003
Posts
8,141
Location
East Sussex
The $_SERVER superglobal is populated by the webserver so the contents can differ between different set-ups. I recommend creating a little script on the live server with the following:

Code:
<?php print_r($_SERVER); ?>

You'll want to hit that script through your web browser as opposed to executing on the CLI. View the source or wrap the above in <pre> elements to get the output in a readable format.

Needless to say, this is a good example of why it's helpful to have your development and live environments matching up as much as possible.
 
Soldato
Joined
19 Jul 2009
Posts
7,243
I can't remember what it is now, but windows PHP has a different superglobal for request_uri.

But as above, developing on windows for a linux live environment is not something that's clever. I spent weeks relatively recently debugging a windows PHP website for deployment on an Amazon, CentOS based server. There's loads of weird idiosyncratic differences.
 
Associate
Joined
24 Oct 2014
Posts
387
Location
South coast
As sniffy says, take a look at what's in the $_SERVER variable.

If you want a pretty output of everything, make yourself a PHPInfo file - call it info.php and stick in it
<?php phpinfo(); ?>
It'll tell you every setting available in PHP and what they're set to, and you can match up the data.

From my code snippets I keep in Evernote, this should help you do things cross-platform:
PHP:
if(!isset($_SERVER['REQUEST_URI']) && strtoupper(substr(PHP_OS, 0, 3) == 'WIN') {
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
    if($_SERVER['QUERY_STRING']) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}
 
Back
Top Bottom