Get Visible URL

I am wondering how I can get the URL (visible in the panel). I tried to do this, and many answers write this:

$url= "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

But it will get the path to the file you are in. I would just like to get a visible url like this:

www.something.com/index.php?page=teams

And then only get the url you can see, not the url included. When I do this, something like:

 www.something.com/search.php

because im prints the url inside the included search.php file.

I hope you understand my question, although it is poorly written, it is very difficult for me to explain my problem.

+3
source share
3 answers

for url: $_SERVER['REQUEST_URI']

after? in url:$_SERVER['QUERY_STRING']

+3
source

This can help:

public function getUri()
{
    if (!isset($_SERVER['REQUEST_URI']) or !isset($_SERVER['SCRIPT_NAME'])) {
        return '';
    }
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
    $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) {
    $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
if (strncmp($uri, '?/', 2) === 0) {
    $uri = substr($uri, 2);
}
$uri = parse_url($uri, PHP_URL_PATH);
// Do some final cleaning of the URI and return it
    return str_replace(array('//', '../'), '/', trim($uri, '/'));
}
0
source

Use $_SERVER['REQUEST_URI']

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

0
source

All Articles