Jump to content

php self to include full url


cloudll

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

Link to comment
https://forums.phpfreaks.com/topic/292897-php-self-to-include-full-url/
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.


$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;
}

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;
}

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.