php文件在localhost上运行良好,但在Web服务器上却无法运行
大家好,我已经和一个问题争论了好几个月了。我有一个php程序,可以在本地主机上完美运行,但其中一个php文件拒绝在webserver.ie上运行。上传后在我的网站上。所有其他php文件都可以工作,但register.php文件拒绝在Web服务器上工作。原因可能是什么。我做错了什么。请帮忙php文件在localhost上运行良好,但在Web服务器上却无法运行,php,webserver,localhost,Php,Webserver,Localhost,大家好,我已经和一个问题争论了好几个月了。我有一个php程序,可以在本地主机上完美运行,但其中一个php文件拒绝在webserver.ie上运行。上传后在我的网站上。所有其他php文件都可以工作,但register.php文件拒绝在Web服务器上工作。原因可能是什么。我做错了什么。请帮忙 // register.php code <?php include('header.php'); include('navbar_teacher.php')
// register.php code
<?php
include('header.php');
include('navbar_teacher.php');
include 'core/init.php';
logged_in_redirect();
if (empty($_POST) === false) {
$required_fields = array('username ','password','password_again','first_name','class','mac','phone_no','email','js1','js2','address');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true) {
$errors[] = 'Sorry, the username \''. $_POST['username'].'\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) === true) {
$errors[] = 'Your username must not contain any space.';
}
if (strlen($_POST['password']) < 6 ) {
$errors[] = 'Your password must be at least 6 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your password do not match.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)=== false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, the email \''. $_POST['email'].'\' is already in use.';
}
}
}
?>
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<body id="class_div">
<div class="span8" id="content">
<div class="row-fluid">
<?php include('about.php'); ?>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<?php include 'add_register.php';?> <!-- block -->
</body>
</html>
<?php
}
include 'includes/overall/footer.php';?>
//register.php代码
//init.php代码
<?php
session_start();
//error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
if(logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'user_id','username','password','first_name', 'last_name','class','mac','phone_no','email','address','email_code','active','password_recover','type','allow_email','profile');
if (user_active($user_data['username']) === false) {
session_destroy();
//header('Location: index.php');
echo("<script>location.href = 'index.php=$msg';</script>");
exit();
}
if ($current_file !== 'changepassword.php' && $user_data['password_recover']== 1) {
header('Location: changepassword.php?force');
exit();
}
}
//echo $user_data['type'];
$errors = array();
?>
//users.php code
<?php
function register_user($register_data) {
array_walk($register_data, 'array_sanitize');
$register_data['password'] =md5($register_data['password']);
$fields = '`' . implode('`, `', array_keys($register_data)) . '`';
$data = '\'' . implode('\', \'', $register_data) . '\'';
$db->query(("INSERT INTO `users` ($fields) VALUES ($data)");
email($register_data['email'], 'Activate your account', "Hello " . $register_data ['first_name'] . ",\n\n You need to activate your account, so use the link below:\n\nhttp://ckischools.org/personal/activate.php?email=" . $register_data['email'] . "&email_code=" .$register_data['email_code'] . "\n\n -ckischools ");
}
//users.php代码
不确定这是否是原因-但我会将包含顺序更改为:
include('core/init.php');
include('navbar_teacher.php');
include('header.php');
因为您在core/init.php
中启动了一个会话,必须在任何输出之前启动该会话
您可以通过测试会话是否已实际创建来添加进一步的检查:
$sessionStarted = session_start();
if($sessionStarted)
{
// code here
}
else
{
// echo('Could not start session!');
}
不确定这是否是原因-但我会将包含顺序更改为:
include('core/init.php');
include('navbar_teacher.php');
include('header.php');
因为您在core/init.php
中启动了一个会话,必须在任何输出之前启动该会话
您可以通过测试会话是否已实际创建来添加进一步的检查:
$sessionStarted = session_start();
if($sessionStarted)
{
// code here
}
else
{
// echo('Could not start session!');
}
我终于找到了解决问题的办法,谢谢你的贡献。我会找到问题所在,找到我所推荐的完美解决方案。
问题出在登记表和提交表上
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
//初始形式
-
用户名*:
-
密码*::提示-至少6个字符
-
再次输入密码*:
-
名字*:
-
姓氏:
-
学生班级:
-
唯一地址:
-
电话号码:
-
电邮*:
-
联络地址:
//初始提交表格
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
我终于找到了问题的解决方案,谢谢你的贡献。我会找到问题所在,找到我所推荐的完美解决方案。
问题出在登记表和提交表上
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
//初始形式
-
用户名*:
-
密码*::提示-至少6个字符
-
再次输入密码*:
-
名字*:
-
姓氏:
-
学生班级:
-
唯一地址:
-
电话号码:
-
电邮*:
-
联络地址:
//初始提交表格
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
存储这些php文件的根目录中是否有.htaccess文件或web.conf文件。如果设置不正确,有时您可能会遇到这些问题。还要确保服务器的php.ini文件设置正确。但是register.php文件拒绝在Web服务器上工作。解释拒绝工作意味着什么,你是否有任何错误?查看错误日志。它可以告诉我们很多事情。您对查询非常开放,应该真正使用它,而不是连接查询。特别是,由于您根本没有转义数据,如果用户输入,
-签名或以反斜杠结束输入,则当前查询将失败。不要使用md5()
进行密码哈希。这很不安全。使用PHP的和。如果您运行的PHP版本低于5.5,则可以使用获得相同的功能。在存储这些PHP文件的根目录中是否有.htaccess文件或web.conf文件。如果设置不正确,有时您可能会遇到这些问题。还要确保服务器的php.ini文件设置正确。但是register.php文件拒绝在Web服务器上工作。解释拒绝工作意味着什么,你是否有任何错误?查看错误日志。它可以告诉我们很多事情。您对查询非常开放,应该真正使用它,而不是连接查询。特别是,由于您根本没有转义数据,如果用户输入,
-签名或以反斜杠结束输入,则当前查询将失败。不要使用md5()
进行密码哈希。这很不安全。使用PHP的和。如果您运行的PHP版本低于5.5,您可以使用获得相同的功能。感谢大家的评论,我已经尝试了一些建议,但仍然不起作用,我重新排列了代码include('core/init.PHP');包括('navbar_teacher.php');包括('header.php');但是register.php文件拒绝在Web服务器上工作。这意味着我添加的任何用户都不会插入到我的数据库中。这就是为什么我将init.php文件和users.php文件包含到我的question@oduswale我认为,正如问题评论中提到的,你需要详细说明“拒绝工作”——目前我们不知道这意味着什么。什么是/没有发生,使您认为它不起作用?是否将$db
设置为全局变量?我认为它不在您的register\u user()
functionMacro-man的范围内-在填写表单并单击提交后拒绝向数据库添加数据如果数据在我的Web服务器上,则不会提交,但如果数据在本地服务器上,则会提交谢谢大家的评论,我已经尝试了一些suggetsion,但是仍然不起作用,我重新排列了代码include('core/init.php');包括('navbar_teacher.php');包括('header.php');但是register.php文件拒绝在Web服务器上工作。这意味着我添加的任何用户都不会插入到我的数据库中。这就是为什么我将init.php文件和users.php文件包含到我的question@oduswale我认为,正如问题评论中提到的,你需要详细说明“拒绝工作”——目前我们不知道这意味着什么。什么是/没有发生使您认为它不起作用的事情?是$db