2013-11-22 34 views
0

我的hostname时PHP包括托管

http://gvidas.lhosting.info

里面HEAD我

<?php include("http://gvidas.lhosting.info/includes/header.php"); ?> 

该文件的物理位置是在/htdocs/includes/header.php

为什么它不工作?我应该使用相对路径吗?

片段的的index.php

根/ htdocs中/ index.php的:

<!DOCTYPE HTML> 
<HTML> 
<HEAD> 
    <?php include("includes/header.php"); ?> 
    <?php if (isset($_SESSION["admin_id"])) { redirect("managePage.php"); } ?> 
    <?php $permision = "public"; ?> 
</HEAD> 
    <BODY> 

    <...> 

    </BODY> 
</HTML> 

的header.php的片段

根/ htdocs中/包括/ header.php文件:

<?php require_once ("../includes/session.php"); ?> 
<?php require_once ("../includes/functions.php"); ?> 


<?php $db = mysqli_connect('http://gvidas.lhosting.info/', 'user', 'pass', 'beta'); 
     if(mysqli_connect_errno()) { die("Database connection failed: " . 
     mysqli_connect_error() . " (" . mysqli_connect_errno() . ")"); 
     } 
?> 

我现在觉得应该用

<?php require_once ("session.php"); ?> 

<?php require_once ("../includes/session.php"); ?> 

有什么想法innstead?

回答

3

大多数Live服务器不会允许绝对的包括。您可以更新代码,如下所示:

<?php include("includes/header.php"); ?> 

相对路径将取决于您将文件包括在哪里。上面的例子假设这个include()函数是从web根目录的文件中调用的。

+0

这个./或../不工作:( –

+0

显示你的目录结构你在哪里调用include()函数? – BenM

+0

这是我的结构:http://postimg.org/image/vge1ouy4h /我从index.php调用它 –

3

您应该使用物理位置而不是URI。

<?php include("/htdocs/includes/header.php"); ?> 
0

试试这个代码

$path = $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_NAME']; 

<?php include("$path/includes/header.php"); ?> 
1

您不能使用网络地址作为路径包括/需要,使用物理路径,而不是像/htdocs/includes/header.php