Quick Search:
 
 PHP Code: Fix missing $_SERVER SCRIPT_URL variable Jump to:  
Category: >> PHP Code >> Fix missing $_SERVER SCRIPT_URL variable  

<< lastnext >>

Snippet Name: Fix missing $_SERVER SCRIPT_URL variable

Description: Many scripts rely on $_SERVER[SCRIPT_URL] which is sometimes missing. This function detects it from other server variables and fixes the missing field.

Also see:
» Read GET URL Variables Into An Associa...
» Fix missing $_SERVER SCRIPT_URL variab...
» Checking Server Status with PHP
» Declaring Variables
» Call subroutine and pass variable by v...
» SEQUENCE: get sequence value into vari...
» Anonymous blocks: Constants and Variab...
» GET and POST variables in hidden form
» Variable Speed Horiz Scroll
» Get file in as variable

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

/**
 * Tries to determine Servers' SCRIPT_URL, if it doesn't exist.
 * The missing superglobal $_SERVER array element will be fixed.
 *
 * Example: client requests ... 
 * http://www.hostname.com/testpage.html?param=value&foo=bar
 *
 * ...$_SERVER['SCRIPT_URL'] is (or becomes)
 * "/testpage.html"
 */
FUNCTION get_script_url() 
{
    $script_url = NULL;
 
    IF (!EMPTY($_SERVER['SCRIPT_URL']))   
        $script_url = $_SERVER['SCRIPT_URL'];
 
    ELSEIF (!EMPTY($_SERVER['REDIRECT_URL'])) 
        $script_url = $_SERVER['REDIRECT_URL'];
 
    ELSEIF (!EMPTY($_SERVER['REQUEST_URI'])) {
        $p = PARSE_URL($_SERVER['REQUEST_URI']);
        $script_url = $p['path'];
    }
 
    ELSE DIE (__FILE__." / ".__FUNCTION__.':<br />Couldn\'t determine $_SERVER["SCRIPT_URL"].');
 
    $_SERVER['SCRIPT_URL'] = $script_url;
 
    return $script_url;
 
} // get_script_url()


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org