我已将文件上传到生产服务器,我的包含似乎无法正常工作

发布于 2024-08-23 14:48:13 字数 2205 浏览 7 评论 0原文

它们在我的 XAMMP 沙箱上都运行良好,但现在什么也没有了。

我做错了什么。

代码如下:

index.php

包含大量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;  

            }


?>

Mass include

包含我的所有内容

<?php

/*Mass include - mass.php*
*Includes all thing needed for operations to start*/


//Grab Header design & details

    require("header.html");

//Grab Footer design & details

    require("footer.html");

//Grab include to connect to the database!

    require("dbcon.php");


?>

Thanx。

They were all working fine on my XAMMP sandbox but now nothing.

Something im doing wrong.

Here is the code:

index.php

Contains mass include, which basically has all the includes in it.

<?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;  

            }


?>

Mass include

contains all of my includes

<?php

/*Mass include - mass.php*
*Includes all thing needed for operations to start*/


//Grab Header design & details

    require("header.html");

//Grab Footer design & details

    require("footer.html");

//Grab include to connect to the database!

    require("dbcon.php");


?>

Thanx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

記柔刀 2024-08-30 14:48:13

一个很常见的问题原因包括更换服务器时“无法工作”:

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

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

  • 使用 require,而不是 include ;如果要求不起作用,你会得到一个致命错误
    • 并启用 error_reportingdisplay_errors 以查看错误消息。
  • 始终使用绝对路径来指向您所包含的文件,而不是相对路径
    • 当然,您不想在代码中输入绝对路径
    • 因此,您可以使用 dirname 函数,有点像这:

在你的文件“main”中(同样的想法应该用于所有其他包含)

require dirname(__FILE__) . '/includes/mass.php';

请注意,dirname(__FILE__)将始终为您提供目录的绝对路径您写入的文件是。

关于“启用错误报告和显示”,因为您可能无权访问服务器的配置文件,最简单的方法是将这样的内容放在主脚本的顶部:

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

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

A quite common cause of trouble about includes that "don't work" when changing servers are :

  • You developped on a Windows machine, and your production server is a Linux machine ;; files names and pathes are case-sensitive on Linux
    • Which means you should check if lower and upper case in your files and directories names do match what you're using.
  • Another problem is files not being found...

About the second problem, two ideas :

  • Use require, instead of include ; you'll get a Fatal Error if the require doesn't work
    • And enable error_reporting and display_errors, to see the error message.
  • Always use absolute paths to point to the files you are including, and never relative ones
    • Of course, you don't want to type the absolue pathes in your code
    • So, you can use the dirname function, a bit like this :

In your file "main" (And the same idea should be used for all other includes) :

require dirname(__FILE__) . '/includes/mass.php';

Note that dirname(__FILE__) will always give you the absolute path to the directory the file you're writting this in is.

About the "enable errors reporting and dislay", as you probably don't have access to your server's configuration files, the simplest way is to put something like this at the top of your main script :

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

With that, errors should be displayed in the browser -- it'll be a bit easier to see them than having to take a look at the server's error log.

无声无音无过去 2024-08-30 14:48:13

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

The production server may not have . in include_path. To fix this, add it to the includes, e.g. ./header.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文