3

Possible Duplicate:
How do I get current page full URL in PHP

How can i get url of the current page using php? Is there any such php function?

What i want to achieve is:

  1. Somehow get the url of the current page
  2. check if the url is equal to some preset value
  3. if it is equal then echo something else echo something else
Community
  • 1
  • 1
user1373168
  • 167
  • 2
  • 4
  • 9
  • That page may be a duplicate, but the accepted answer that cites `$_SERVER['PATH_INFO']` appears to be invalid for some systems. (at least it doesn't work on mine; I'm using PHP 5.3.0 under Apache) – Jason S May 08 '12 at 18:59
  • 1
    This is _not_ an exact duplicate of the linked question. This one is of PHP in general, while the one linked was specifically about an IIS environment where the general method wouldn't work. – Core Xii May 08 '12 at 19:00
  • @CoreXii - I'll re-open if you edit to reference the other question and explain in the body of this question why this case is different. Just @ me in these comments rather than flagging. Cheers. – Kev May 08 '12 at 23:44
  • @JasonS - see my comment above. – Kev May 08 '12 at 23:45

1 Answers1

11
<?php
    $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    echo $url;
?>
Colin Brock
  • 21,267
  • 9
  • 46
  • 61
Kris.Mitchell
  • 998
  • 4
  • 17
  • 34
  • 6
    You're not taking alternate protocols into account, e.g. HTTPS. At least `$_SERVER['SERVER_PROTOCOL']` can be used to extract it. – Core Xii May 08 '12 at 19:03