William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

PHP $_SERVER variables

To refer the script itself, we have 4 optional variables:


The first three are exactly the same, they are all relative to URL, represent the current running script file.
The last one, $_SERVER[HTTP_REFERER], normally used in a parent-child/context env (frameset, <form…>) to refer to parent’s script name.

When I run phpinfo.php in my pc’s xampp env, they look like the following:

  • $_SERVER[“REQUEST_URI”]: /xampp/phpinfo.php
  • $_SERVER[“SCRIPT_NAME”]: /xampp/phpinfo.php
  • $_SERVER[“PHP_SELF”]: /xampp/phpinfo.php
  • $_SERVER[“HTTP_REFERER”]: http://localhost/xampp/navi.php

$_SERVER[’PHP_SELF’] and $_SERVER[’SCRIPT_NAME’] reprent script name, without passed parameters;
On the other side, $_SERVER[‘REQUEST_URI’] will be with the parameters, e.g: /example/index.php?a=test.

Normally I use largely $_SERVER[‘PHP_SELF’] in my codes to call the default php script; and $_SERVER[“HTTP_REFERER”] to refer to parent’s script.

A good reference is at: http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm


2 responses to “PHP $_SERVER variables

  1. Roxanne Byles 02/21/2011 at 12:05 pm

    Excellent article. I was checking constantly this blog and I am impressed! Very helpful info particularly the last part. I care for such info much. I was looking for this certain info for a long time. Thank you and good luck.

  2. theserveradminn 12/15/2011 at 4:49 am

    Nice post man. I am also Blogging about server over at http://www.the-server-admin.com/. I am going to link to your blog looks like there is some good stuff here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: