DEV Community

siddharth shukla
siddharth shukla

Posted on

Current url fetch in php

?php

$request_url = “http://{$_SERVER[‘HTTP_HOST’]}{$_SERVER[‘REQUEST_URI’]}”;

echo $request_url;

?>

Read More: https://realprogrammer.in/current-url-fetch-in-php/

Top comments (1)

Collapse
 
dharnarh profile image
Umar Farouq Mohammed

Here is a better one with dynamic protocol for site name
<?php

$requestUrl = $_SERVER['REQUEST_URI'];

$siteName = $_SERVER['SERVER_NAME'];
$siteAddr = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https://" : "http://") . $siteName;

?>