Jump to content

php self to include full url


cloudll
 Share

Recommended Posts

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

Edited by cloudll
Link to comment
Share on other sites

I haven't had the "pleasure" of running into this problem because I only run on Linux. However, the question intrigued me and I did some digging and found some other people who had similar experiences. It seems that PHP running on Windows has an empty:

$_SERVER[REQUEST_URI] 

Here is one article with a workaround. http://davidwalsh.name/iis-php-server-request_uri

You can try it and see if it's something you can work with. There is a solution, maybe not this one, but there is a one out there.

  • Like 1
Link to comment
Share on other sites


$current_url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER['QUERY_STRING'])) {
    $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
    $current_url .= "?" . $query_string;
}
Link to comment
Share on other sites

I guess can improve on this with the scheme as well

$_SERVER['REQUEST_SCHEME'] also has issues, so will just test for https

if (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$scheme = "https";
} else {
$scheme = "http";
}
$current_url = filter_var($scheme."://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER['QUERY_STRING'])) {
    $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
    $current_url .= "?" . $query_string;
}
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.