Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的include似乎不起作用,因为我已经将文件上传到了生产服务器_Php_Nested_Include_Server Side Includes - Fatal编程技术网

Php 我的include似乎不起作用,因为我已经将文件上传到了生产服务器

Php 我的include似乎不起作用,因为我已经将文件上传到了生产服务器,php,nested,include,server-side-includes,Php,Nested,Include,Server Side Includes,他们都在我的沙箱上工作得很好,但现在什么都没有了 我做错了什么 代码如下: index.php 包含mass include,它基本上包含了所有的include <?php //Starting session session_start(); //Includes mass includes containing all the files needed to execute the full script //Also shows homepage elements withou

他们都在我的沙箱上工作得很好,但现在什么都没有了

我做错了什么

代码如下:

index.php

包含mass include,它基本上包含了所有的include

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

include ("includes/mass.php");

//Login Form

$login = 


         "<form id='signin' action = 'login.php' method = 'POST'>
         Username<input type= 'text' name= 'username'>
         Password<input type= 'password' name= 'password'>
         <input type= 'submit' value='login' name='submit'>
         </form>";

//Calculate number of users online

$num_users_sql = mysql_query("SELECT * FROM user WHERE loggedin = '1' ", $con);

$num_online_users = mysql_num_rows($num_users_sql);

//user bash link

$user = "<a href='user.php'>User</a><br>";  

//Register Form Link     

$registerlink = "<a id='signup' href='register.php'>Sign Up</a>";

//Logged In User Links 

$logoutlink   = "<a id='logoutlink' href='logout.php'>Log out</a>";

$message = "<div id='welcome'>"."Hello"." ".$_SESSION['username']."!"."</div>";

$num_users_online = "<div id='users_online'><h2>There are ".$num_online_users." Users On Readnotes Right nw!</h2>"."</div>";

         if (isset($_SESSION['username']))

          //If user is logged in

            {

                echo $message;

                echo $user;

                echo "</br>";

                echo $num_users_online;

                echo $logoutlink;

            }

         //If user is logged out

         else

            {   
                echo $login;

                echo $registerlink;  

            }


?>

生产服务器的
包含路径中可能没有
。要解决此问题,请将其添加到includes中,例如
/header.html

更改服务器时导致includes“不工作”的常见故障原因有:

  • 您在Windows机器上开发,而您的生产服务器是Linux机器;;Linux上的文件名和路径区分大小写
    • 这意味着您应该检查文件和目录名称中的大小写是否与您正在使用的名称匹配
  • 另一个问题是找不到文件

关于第二个问题,有两个想法:

  • 使用,而不是;如果require不起作用,您将得到一个致命错误
    • 并启用
      错误报告
      显示错误
      ,以查看错误消息
  • 始终使用绝对路径指向包含的文件,而不要使用相对路径
    • 当然,您不想在代码中键入绝对路径
    • 所以,你可以使用这个函数,有点像这样:

在您的文件“main”中(所有其他include都应使用相同的思想):

请注意,
dirname(\uuuu FILE\uuuu)
将始终为您提供写入此文件的目录的绝对路径


关于“启用错误报告和dislay”,由于您可能无法访问服务器的配置文件,最简单的方法是在主脚本的顶部放置以下内容:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

这样,错误就应该显示在浏览器中——查看它们比查看服务器的错误日志要容易一些。

现在呢?你的问题在哪里?秋葵的意思是:“在你的情况下,“它不起作用”是什么意思?”;;你有没有收到任何错误消息?没有错误消息没有。我只是没有看到我的模板,也没有得到mysql连接。这意味着服务器基本上不存在include。我认为路径可能不同,但我不太擅长服务器的这方面。顺便说一句,它的名字很便宜。如果这能提供更多信息的话。你查看服务器的错误日志了吗?是的。显然,服务器没有指向所需的文件。
require dirname(__FILE__) . '/includes/mass.php';
error_reporting(E_ALL);
ini_set('display_errors', 'On');