Php 主机中的头函数故障
我正在编写一个简单的登录系统。它在本地运行得非常好,但是当我在主机中运行时,我的头函数遇到了麻烦 这是我的登录表:Php 主机中的头函数故障,php,html,mysql,sql,Php,Html,Mysql,Sql,我正在编写一个简单的登录系统。它在本地运行得非常好,但是当我在主机中运行时,我的头函数遇到了麻烦 这是我的登录表: <form method="post" action="auth.php"> User:<br /> <input type="text" name="name" required><br /><br /> Password:&
<form method="post" action="auth.php">
User:<br />
<input type="text" name="name" required><br /><br />
Password:<br />
<input type="password" name="pass" class="input" required><br /><br />
<button>LOGIN</button>
</form>
以及auth.php:
include '../conection.php';
$user = $mysqli->real_escape_string($_POST['name']);
$pass = sha1($mysqli->real_escape_string($_POST['pass']));
if(isset($user)){
$users = $mysqli->query("select * from admins where admin_user='".$user."' and admin_pass='".$pass."' ");
if($users->fetch_object()){
session_start();
$_SESSION['user'] = $user;
//Im having troubles with this function
header('Location:control.php');
exit;
}else{
echo 'Sorry no access<br /><br />';
//if i remove the "//" to the next header function works in local and hosting
//header('Location:index.php');
}
}else{
echo 'Sorry no access<br /><br />';
}
$mysqli->close();
警告:
第一:会话\u启动:无法发送会话缓存限制。
第二:无法修改标题信息
代码中有什么错误?或者我没有考虑什么?
此外,如果您有任何建议,以改善这段代码,我真的很感激
感谢您的帮助。首先使用准备好的语句 第二,这样做:
header('Location: control.php');
exit;
header函数将原始HTTP头发送到客户端
重要的是要注意,在发送任何实际输出之前必须调用header使用下面的代码,我将代码更改为action=并向新的submit按钮添加一个。以后你可以把它们分开 不要将LOGIN与ifisset$\u POST['submit']条件语句一起使用,它将不起作用。它基于我在下面包含的新提交按钮 要首先概述错误,请执行以下操作: 如果$us=$users->fetch_对象-$us是一个没有做任何事情的杂散变量;它需要被移除 该行需要读取为$users->fetch\u对象 以下内容也需要删除;没有对应的if条件:
else{
echo 'Sorry no access<br /><br />';
}
您应该考虑使用准备好的语句,并使用PHPTRY更改文件的名称。将其改为authenticate.php,而不是auth.php。我也有这个奇怪的问题before@RobertDeanPantino我不认为文件名有什么不同。你试试看吗?删除auth.php并将操作更改为authenticate.php,或者如果需要,可以使用window.location.href=control.php而不是header@RobertDeanPantinoauth.php只是一个例子。谢谢,普乌姆!弗雷德:我真的很感谢你的帮助,你的回答很有帮助,很有效。我希望有一天能报答你的恩惠。还有一个小问题:你建议我继续学习什么?问候你。@Christian你很受欢迎Christian。你可以仔细阅读,或者,它们更安全。他们的工作要多一些,但是值得付出努力,相信我。另外,如果你有什么特别的想法,Stack是一个很好的地方,可以浏览许多问题和公认的答案。你也可以用谷歌搜索,很多时候,谷歌很可能会把你带回到堆栈上:@Christian我建议你使用的另一个东西是或PHP5.5的函数。对于小于5.5的PHP,请使用。sha1不是最好的散列方法;很多人不再喜欢使用它了。谢谢你的建议和花时间回复。我们很快就开始读书了。
else{
echo 'Sorry no access<br /><br />';
//if i remove the "//" to the next header function works in local and hosting
header('Location:index.php');
}
<?php
include '../conection.php';
$user = $mysqli->real_escape_string($_POST['name']);
$pass = sha1($mysqli->real_escape_string($_POST['pass']));
if(isset($_POST['submit'])){
$users = $mysqli->query("select * from admins where admin_user='".$user."' and admin_pass='".$pass."' ");
if($users->fetch_object()){
session_start();
$_SESSION['user'] = $user;
//Im having troubles with this function
header('Location:control.php');
exit;
// echo $user; // don't use this with header
}else{
// echo 'Sorry no access<br /><br />'; // don't use this with header
//if i remove the "//" to the next header function works in local and hosting
header('Location:index.php');
exit;
}
} // brace for if(isset($_POST['submit']))
$mysqli->close();
?>
<form method="post" action="">
User:<br />
<input type="text" name="name" required><br /><br />
Password:<br />
<input type="password" name="pass" class="input" required><br /><br />
<input type="submit" name="submit" value="Submit">
<br>
</form>