简体   繁体   English

Web服务器中的根目录

[英]root directory in a web server

All my work on php and mysql was on local server.Now i want to move to a web host.I choose one of the free hosting sites like 1freehosting.I uploaded my php pages to the file manager of the hosting site's cpanel. 我在php和mysql上所做的所有工作都在本地服务器上。现在我想移至虚拟主机。我选择了1freehosting等免费托管站点之一。我将php页面上传到了托管站点cpanel的文件管理器中。

I used to access the index.php under the folder name 'core' page on my local server like the following : 我以前在本地服务器上的文件夹名称'core'页面下访问index.php ,如下所示:

localhost/practice/core/index.php

I wrote the url with my domain name but got error .My domain name is ezphp.tk(it's also a free domain) 我用我的域名写了网址,但出现错误。我的域名是ezphp.tk(这也是一个免费域名)

ezphp.tk/practice/core/index.php

But i got the following error 但是我遇到了以下错误

Warning: require_once(../classes/Cookie.php): failed to open stream: No such file or directory in /home/u377815502/public_html/practice/core/init.php on line 42 警告:require_once(../ classes / Cookie.php):无法打开流:在第42行的/home/u377815502/public_html/practice/core/init.php中没有此类文件或目录

Fatal error: require_once(): Failed opening required '../classes/Cookie.php' (include_path='.:/usr/lib/php') in /home/u377815502/public_html/practice/core/init.php on line 42 致命错误:require_once():无法在/home/u377815502/public_html/practice/core/init.php中打开所需的'../classes/Cookie.php'(include_path ='。:/ usr / lib / php') 42行

My file structure in the host server is the following : 我在主机服务器中的文件结构如下:

root directory as i see is the following : 我看到的根目录如下:

file manager>practice> 文件管理器>实践>

inside practice i have the following folders: 内部练习中,我具有以下文件夹:

-classes-core-css-includes-function-editor -classes-core-css-includes-function-editor

my index.php is the following : 我的index.php是以下内容:

<?php 

    require_once '../core/init.php';
    include('../includes/header.php');
    if(Session::exists('home')){
        echo '<p>'.Session::flash("home").'</p>';

    }


    if($user->isLoggedIn()){



?>
<p>Hellow <a href="../includes/profile.php?user=<?php echo escape($user->data()->username); ?>"><?php echo escape($user->data()->username); ?> </a>!</p>
<ul>
    <li><a href='../includes/logout.php'>logout</a></li>
    <li><a href='../includes/update.php'>update info</a></li>
    <li><a href='../includes/changepassword.php'>change your password</a></li>
    <li><a href="../includes/profile.php<?php echo '?user='.escape($user->data()->username);?>">profile</a></li>

</ul>
<?php
      if($user->hasPermission('moderator')){
          echo '<p>you ara a moderator</p>';
      }
    }else{

        echo '<p>you need to <a href="../includes/login.php">login</a> or <a href="../includes/register.php">register</a><p>';
    }
include('../includes/footer.php');
    ?>

Use $_SERVER['DOCUMENT_ROOT'] instead of using relative paths: 使用$_SERVER['DOCUMENT_ROOT']而不是使用相对路径:

require_once $_SERVER['DOCUMENT_ROOT'].'/core/init.php';
include($_SERVER['DOCUMENT_ROOT'].'/includes/header.php');

Use this inside your other files as well, so that it's not trying to traverse odd paths. 也可以在其他文件中使用它,这样它就不会尝试遍历奇数路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM