Why do some PHP installations have $_SERVER['SCRIPT_URI'] and others not?

后端 未结 3 472
孤城傲影
孤城傲影 2021-01-19 06:28

I run two Apache 2 servers. One has PHP5.2 and the other has PHP5.3. Is there a reason why on the 5.3 machine has $_SERVER[\'SCRIPT_URI\']?

Where does t

3条回答
  •  迷失自我
    2021-01-19 06:57

    I moved to CentOS 7 with Plesk12, PHP 5.6.6 and rewrite on etc. SCRIPT_URI has not been there. And because it is so nice to use in some situations I wrote this workaround:

    if(!isset($_SERVER['SCRIPT_URI'])){
        $_SERVER['SCRIPT_URI'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    
        $pos = strrpos($_SERVER['SCRIPT_URI'],'/');
        if($pos!==false) {
            $_SERVER['SCRIPT_URI'] = substr($_SERVER['SCRIPT_URI'], 0, $pos+1);
        }
    }
    

    As I am not a total expert, please review this code to your specific application before plugging it in. On my system it seems to work perfectly. I just put it in the Head-Area of my index.php and others.

提交回复
热议问题