PHP脚本无法获取正确的主页

PHP脚本无法获取正确的主页,php,function,server,root,Php,Function,Server,Root,此脚本是一个函数,用于定义站点url以将其发送到大脚本,但由于它是共享宿主,因此它得到了不正确的路径。如何告诉它正确的站点路径?我想直接告诉它站点url和脚本目录,脚本认为这是路径/hermes/bosnaweb23a/index.php,但正确的路径只有/index.php。 我想删除/hermes/bosnaweb23a/ 因为/hermes/bosnaweb23a/是共享的托管路径 <?php function home_base_url(){ $base

此脚本是一个函数,用于定义站点url以将其发送到大脚本,但由于它是共享宿主,因此它得到了不正确的路径。如何告诉它正确的站点路径?我想直接告诉它站点url和脚本目录,脚本认为这是路径/hermes/bosnaweb23a/index.php,但正确的路径只有/index.php。 我想删除/hermes/bosnaweb23a/ 因为/hermes/bosnaweb23a/是共享的托管路径

<?php 

    function home_base_url(){
        $base_url = (isset($_SERVER['HTTPS']) &&
        $_SERVER['HTTPS']!='off') ? 'https://' : 'http://';
        $tmpURL = dirname(__FILE__);
        $tmpURL = str_replace(chr(92),'/',$tmpURL);
        $tmpURL = str_replace($_SERVER['DOCUMENT_ROOT'],'',$tmpURL);
        $tmpURL = ltrim($tmpURL,'/');
        $tmpURL = rtrim($tmpURL, '/');

        if (strpos($tmpURL,'/')){
            $tmpURL = explode('/',$tmpURL);
            $tmpURL1 = $tmpURL[0];
            $tmpURL2 = $tmpURL[1];
            $tmpURL = $tmpURL1;
            if(!empty($tmpURL2)) $tmpURL .= '/'.$tmpURL2;
        }

        if ($tmpURL !== $_SERVER['HTTP_HOST'])
            $base_url .= $_SERVER['HTTP_HOST'].'/'.$tmpURL.'/';
        else
            $base_url .= $tmpURL.'/';

        $base_url = str_replace('//','/',$base_url);
        $base_url = str_replace('http:/','http://',$base_url);
        $base_url = str_replace('https:/','https://',$base_url);

        return str_replace(dirname(__FILE__),'',$base_url); 
    }

    $local_path = dirname(__FILE__).'/';
    $sSoftware = strtolower( $_SERVER["SERVER_SOFTWARE"] );


    function getSlashes() {
        $sSoftware = strtolower( $_SERVER["SERVER_SOFTWARE"] );
        if ( strpos($sSoftware, "microsoft-iis") !== false ) return "\\";
        else return "/";
    }

    if ( strpos($sSoftware, "microsoft-iis") !== false ) {
        $local_path = str_replace(getSlashes(), '/', dirname(__FILE__)).'/';
    }
    function get_domain() {     
        return $_SERVER['HTTP_HOST'];
    }



    $remote_path = home_base_url();

    if((strpos($remote_path, '127.0.0.1') !== false) || (strpos($remote_path, 'localhost') !== false)) {
        $find = str_replace(' ','',":\ ");
        @$local_path = end(explode($find,$local_path));
        define('DOCUMENT_ROOT', '/'.$local_path);
    }else{
        define('DOCUMENT_ROOT', '/'.$local_path);
    }

?>
您可以使用以下代码从/hermes/bosnaweb23a/index.php获取index.php

$url = explode("/", "/hermes/bosnaweb23a/index.php");
$script_name = end($url);

$script\u名称应该是index.php。

您想做什么?试图获取规范url?请指出实际结果和预期结果,以及代码的哪一部分应该获得结果,以及您怀疑错误的地方。在这种情况下,请定义正确和不正确。解释你试图实施的规则。举一个有效的例子。解释你做了哪些调试来缩小问题的范围,因为这里有很多复杂的代码需要处理,并且大致上你认为可能会出错,如果你还没有调试完,请先这样做。目前你对这个问题的描述太模糊了。记住,除了你在这里写的东西,我们对你的代码一无所知。谢谢。我想直接告诉它站点url和脚本目录。脚本认为这是路径/hermes/bosnaweb23a/index.php,但正确的路径是/index.php。我只想删除/hermes/bosnaweb23a/因为/hermes/bosnaweb23a/是碎片托管路径。$_服务器['DOCUMENT\u ROOT']定义了磁盘上的路径。如果要创建URL,这是无用的,因为URL通常不会直接映射到磁盘位置$基本url.$\u服务器[HTTP\u主机]./index.php;我认为,这应该是构建URL所需要的全部。或者,如果不想指定/index.php硬编码,则使用$\u SERVER[SCRIPT\u NAME]替换,前提是需要当前执行脚本的名称。有关可能有用的其他变量,请参见。我想你可能把这个复杂化了。