Link to home
Start Free TrialLog in
Avatar of djsoltan
djsoltan

asked on

php url

hi,

can anyone tell me how i can echo the entire url of the page using php?

for example: <?php echo url ?>

result would be like

http://mysite.com/music.php?id=100

i guess there is a global variable that can be used, but i dono what it is.

thanks
Avatar of steelseth12
steelseth12
Flag of Cyprus image

<?php echo "http://mysite.com/music.php?id=100" ?>

if you want it to be a clickable link

<?php echo "<a href='http://mysite.com/music.php?id=100'>http://mysite.com/music.php?id=100</a>" ?>
Avatar of djsoltan
djsoltan

ASKER

hi,
well i want it to be automatic,,,
so that it makes it on the fly based on the id
i dont want to hard code it for everysingle page since there are so many of them.
so if there is a value that would findout what the current url is, and just echo the entire url would be great.
you want to echo the url of the current page ?
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try:
$uri=$_SERVER[PHP_SELF];

echo( "<a href='{$uri}'>{$uri}</a>");

If that does not work try:

$uri=$_SERVER[PHP_SELF];
echo( "<a href='" . $uri . "'>".$uri."</a>");
I had hoped at first that PHP_SELF would work, but I think it only gives a relative URL.
print "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
This shoud do it:
$uri="";
if( isset($_SERVER['HTTPS']) )
{
      $uri .= "https://";
}
else
{
      $uri .="http://";
}
$uri .= $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

if(isset($_SERVER['QUERY_STRING']))
{
      $uri .= "?".$_SERVER['QUERY_STRING'];
}
echo( "<a href='" . $uri . "'>".$uri."</a>");