scriptygoddess

29 Jan, 2007

Get current URL with PHP

Posted by: Jennifer In: Script snippet

Because I was having a "duh" moment. :)

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

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

6 Responses to "Get current URL with PHP"

1 | Christian

February 6th, 2007 at 3:40 pm

Avatar

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

2 | Jennifer

February 10th, 2007 at 9:34 pm

Avatar

Updated with $_SERVER :)

3 | Louis

November 24th, 2007 at 1:30 pm

Avatar

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

February 9th, 2008 at 2:24 pm

Avatar

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

March 7th, 2008 at 2:01 am

Avatar

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'].'.';}

6 | Streche

February 27th, 2009 at 1:26 am

Avatar

Yea, $.SERVER has a lot of other useful elements too.
http://us3.php.net/manual/en/reserved.variables.server.php

These in particular for getting the complete current URL:
SERVER_PROTOCOL
HTTPS
SERVER_PORT

http://www.code-better.com/php/get-current-url

Comment Form

Featured Sponsors


  • Curt: If anyone comes across this with similar issues I was able to sort out the pagination issues painlessly with easyCommentsPaginate from http://www.mush
  • Christopher: Yeah, it is indeed hard to do. And something remains elusive about why the pagination never worked. I tried everything I could find. Regardless, I
  • Jennifer: Hi Christopher, always hard to bug test stuff like that remotely. Sorry those didn't help. Glad you found a solution though :)

About


Advertisements