PHP program to get the full URL of the currently active pages.
Method 1:
Program to display URL of current page.
<?php
// Program to display URL of current page.
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$link = "https";
else
$link = "http";
// Here append the common URL characters.
$link .= "://";
// Append the host(domain name, ip) to the URL.
$link .= $_SERVER['HTTP_HOST'];
// Append the requested resource location to the URL
$link .= $_SERVER['REQUEST_URI'];
// Print the link
echo $link;
?>
Output:
http://localhost/tutorial/tutorial.php |
Method 2:
Program to display URL of current page.
<?php
// Program to display current page URL.
$link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
"https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
$_SERVER['REQUEST_URI'];
echo $link;
?>
output:
http://localhost/tutorial/tutorial.php |