我是php的新手,所以我们将不胜感激。 我正在尝试提交此表单以进行登录。
<form method="post" action="sign_in_process.php">
<table>
<tr>
<td>
<label>E-mail: </label>
</td>
<td>
<input type="text" id="e_mail_address" name="email" />
</td>
</tr>
<tr>
<td id="e_passwd">
<label>Password: </label>
</td>
<td>
<input type="text" id="passwd" name="pass"/>
</td>
</tr>
</table>
<table>
<tr>
<td id="remember-me">
<input type="checkbox" value="remember" id="remember" />
Remember me
</td>
<td>
<button type="submit" id="sign_in_btn" name="sign_in_btn"></button>
</td>
</table>
</form>
这是我的sign_in_process.php页面
session_start();
if(isset($POST['sign_in_btn']))
{
$user_email=trim($POST['email']);
$user_password=hash("sha256",$POST['pass']);
check_email($user_email);
check_password($user_password);
if(isset($_SESSION['error']))
{
header("Location:sign-in.php");
}
else
{
$query="SELECT * from user WHERE user_email='$user_email' AND user_password='$user_password'";
$retrieve=new retrieve();
$hold=$retrieve-getdata($query);
if($hold['user_active']==1)
{
$_SESSION['login']==true;
$_SESSION['email']=$user_email;
$_SESSION['pass']=$user_password;
$_SESSION['username']=$hold['user_name'];
$_SESSION['user_id']=$hold['user_id'];
header("Location:index.php");
}
else if($hold['user_active']==0)
{
echo "you have to activate your account first by clicking the link we have sent you on your email";
}
else if(!$holder)
{
echo "invalid user";
}
}
}
但是当我尝试登录时,没有任何反应,虽然我可以在URL中看到提交的表单,但它确实转到了sign_in_process.php,但它没有执行任何操作,只是显示一个空白页面。 在上面的代码中,check_email和check_password只是我用于验证的函数,我在我的functions.php文件中。我要求函数类使用require_once。
答案 0 :(得分:1)
我刚刚将下划线添加到$ _POST。 你永远不应该相信用户输入,所以我添加了mysql_real_escape_string(); :) 并且“记住我”按钮中缺少“名称” - 属性
if(isset($_POST['sign_in_btn']))
{
$user_email=trim($_POST['email']);
$user_password=hash("sha256",$_POST['pass']);
check_email($user_email);
check_password($user_password);
if(isset($_SESSION['error']))
{
header("Location:sign-in.php");
}
else
{
$user_email=mysql_real_escape_string($user_email);
$user_password=mysql_real_escape_string($user_password);
$query="SELECT * from user WHERE user_email='$user_email' AND user_password='$user_password'";
$retrieve=new retrieve();
$hold=$retrieve-getdata($query);
if($hold['user_active']==1)
{
$_SESSION['login']==true;
$_SESSION['email']=$user_email;
$_SESSION['pass']=$user_password;
$_SESSION['username']=$hold['user_name'];
$_SESSION['user_id']=$hold['user_id'];
header("Location:index.php");
}
else if($hold['user_active']==0)
{
echo "you have to activate your account first by clicking the link we have sent you on your email";
}
else if(!$holder)
{
echo "invalid user";
}
}
}
?>