Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

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
0
djsoltan
Asked:
djsoltan
  • 3
  • 2
  • 2
  • +2
1 Solution
 
steelseth12Commented:
<?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>" ?>
0
 
djsoltanAuthor Commented:
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.
0
 
steelseth12Commented:
you want to echo the url of the current page ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ZylochCommented:
You can find many snippets online that do this by gluing together the $_SERVER variables. For example, see

http://www.webcheatsheet.com/PHP/get_current_page_url.php
0
 
hieloCommented:
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>");
0
 
ZylochCommented:
I had hoped at first that PHP_SELF would work, but I think it only gives a relative URL.
0
 
steelseth12Commented:
print "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
0
 
hieloCommented:
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>");
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now