Get current URL with PHP

Because I was having a “duh” moment. :)

$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

5 Responses to “Get current URL with PHP”

  1. Christian Says:

    You should be using $_SERVER (for PHP4 and up). Other than that, I know exactly what you mean ;)

  2. Jennifer Says:

    Updated with $_SERVER :)

  3. Louis Says:

    Yea thats one of the things that changed from PHP3 to PHP4. I had forgotten all about it. I just used this in my video app that was assigning an incorrect URL to videos. This variable made the correction. Thanks.

  4. Barry Says:

    This is fun, and very useful:

    if ($_SERVER['HTTP_REFERER']=$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])
    {echo ‘Form came from me’;}
    else
    {echo ‘Form came from spam bot at’.$_SERVER['REMOTE_ADDR'].’.';}

  5. Web Designer Philippines Says:

    What is the use of the ff codes?

    if ($_SERVER['HTTP_REFERER']=$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])
    {echo ‘Form came from me’;}
    else
    {echo ‘Form came from spam bot at’.$_SERVER['REMOTE_ADDR'].’.';}

Leave a Reply

Subscribe without commenting