Page 1 of 1

Putting URL in variable then Echo

Posted: Sat Dec 31, 2011 6:50 pm
by iwmichael
I'm having trouble using PHP to display the current URL in the Address bar. I see I need to use $_SERVER['REQUEST_URI'] but I need it in a variable then echo it later on a page.

Code: Select all

<?php
if(!$id || count($headerinfo) < 1) { echo '<a href="'.$site_url.'">'.$site_name.'</a> / '.$pname.'';
$comments_layout = '1';
$comMents = "";

} else { 
$comments_layout = '2';
$comMents = "<div class="alignleft"> PHP to show Page URL </div>";
?>

HTML Code
<?php echo '$comMents'; ?>
I tried reading some tutorials but I'm not seeing a solution for doing this with PHP.

Re: Putting URL in variable then Echo

Posted: Sat Dec 31, 2011 11:47 pm
by Gopesh
Hi,If u need to get the current url and to store it in a variable check

Code: Select all


$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if ($_SERVER["SERVER_PORT"] != "80")
{
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} 
else 
{
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
//This will echo the url
 echo $pageURL;
//echo with link
echo "<a href=$pageURL'>Url </a>";
Hope it helps u..