/ Published in: PHP
Many scripts rely on `$_SERVER[SCRIPT_URL]` which is sometimes missing. This function detects it from other server variables and fixes the missing field.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Tries to determine Servers' SCRIPT_URL, if it doesn't exist. * The missing superglobal $_SERVER array element will be fixed. * * Example: client requests ... * <samp>http://www.hostname.com/testpage.html?param=value&foo=bar</samp> * * ...$_SERVER['SCRIPT_URL'] is (or becomes) * <samp>"/testpage.html"</samp> * * @return string * @author Carsten Witt <[email protected]> * @version 20100206 */ function get_script_url() { $script_url = null; $script_url = $_SERVER['SCRIPT_URL']; $script_url = $_SERVER['REDIRECT_URL']; $script_url = $p['path']; } $_SERVER['SCRIPT_URL'] = $script_url; return $script_url; } // get_script_url()