我已将文件上传到生产服务器,我的包含似乎无法正常工作
它们在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个很常见的问题原因包括更换服务器时“无法工作”:
关于第二个问题,有两个想法:
require
,而不是include
;如果要求不起作用,你会得到一个致命错误error_reporting
和display_errors
以查看错误消息。dirname
函数,有点像这:在你的文件“main”中(同样的想法应该用于所有其他包含):
请注意,
dirname(__FILE__)
将始终为您提供目录的绝对路径您写入的文件是。关于“启用错误报告和显示”,因为您可能无权访问服务器的配置文件,最简单的方法是将这样的内容放在主脚本的顶部:
这样,错误应该显示在浏览器——看到它们比查看服务器的错误日志要容易一些。
A quite common cause of trouble about includes that "don't work" when changing servers are :
About the second problem, two ideas :
require
, instead ofinclude
; you'll get a Fatal Error if the require doesn't workerror_reporting
anddisplay_errors
, to see the error message.dirname
function, a bit like this :In your file "main" (And the same idea should be used for all other includes) :
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 :
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.
生产服务器在
include_path
中可能没有.
。要解决此问题,请将其添加到包含中,例如./header.html
。The production server may not have
.
ininclude_path
. To fix this, add it to the includes, e.g../header.html
.