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"]

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

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements