• Blogs (9)
    • đŸ“± 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • PHP $_SERVER variables

    Blogs20112011-02-17


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

    • $_SERVER[’PHP_SELF’]
    • $_SERVER[’SCRIPT_NAME’]
    • $_SERVER[‘REQUEST_URI’]
    • $_SERVER[HTTP_REFERER]

    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