[wd_asp elements=’search’ ratio=’100%’ id=1]

Get last part of url – page name

19th November 2020

Php - Miscellaneous

php codehaven

If you need to get the last part of a url of the page you are in, the code below will show you.

1".$uri; // Outputs: URI

$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";

$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo "
2".$url; // Outputs: Full URL

$query = $_SERVER['QUERY_STRING'];
echo "
3".$query; // Outputs: Query String
?>


$path = basename($_SERVER['HTTP_REFERER']);
echo $path;

Shows loop.php