所以我在这里搜索了几天但找不到合适的解决方案,我的问题是我的登录系统准备就绪并且工作但问题是当我在我的复选框被选中时尝试设置cookie时没有设置cookie。 我有三个文件
login.php(实际逻辑)
studentlogin.php
<?php
session_start();
if(isset($_cookie['eno']))
{
header('location:profile.php');
exit();
}
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMS | Login</title>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/processlogin.js"></script>
</head>
<body>
<div id="wrap">
<?php include 'header.php';?>
<div id="content">
<section>
<article id="logform">
<form action="" id="log">
<fieldset>
<legend>Login Here</legend>
<table>
<tr>
<td>
<label for="eno">Enrollment No:<span class='err' id='err_eno'>*Require</span></label>
</td>
</tr>
<tr>
<td>
<input type="text" name="eno" id="eno" value="" placeholder='Enter Enrollment No' required/>
</td>
</tr>
<tr>
<td>
<label for="pw">Password:<span class='err' id='err_pw'>*Require</span></label>
</td>
</tr>
<tr>
<td>
<input type="password" name="pw" id="pw" value="" placeholder='Your Password' required/>
</td>
<tr>
<td>
<input type="checkbox" name="cb" checked="checked">
<label>Keep me signed in.</label>
</td>
</tr>
<tr>
<td colspan='2'>
<span id="err"></span>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" id="submit_btn" value="Login" />
</td>
</tr>
<tr>
<td>
<input type="reset" name="reset" value="Reset" />
</td>
</tr>
<tr>
<td>
<label>New user?<a href="studentregistration.php">Register here</a></label>
</td>
</tr>
<tr>
<td>
<label>Forgot your password?<a href="resetpassword.php">Click here</a></label>
</td>
</tr>
</table>
</fieldset>
</form>
</article>
</section>
</div>
<?php include 'footer.php'; ?>
</div>
</body>
</html>
loginprocess.php
$('#submit_btn').click(function(){
var dataString = $('#log').serialize();
//alert (dataString);return false;
$.ajax({
type:"POST",
url:"script/login.php",
data:dataString,
success:function(x)
{
if(x =='')
{
//Handle Error Here
$('#err').html("<p class='err'>Please provide right combination</p>");
}
else if(x == '1')
{
window.location='profile.php';
}
}
});
return false;
});
的login.php
<?php
error_reporting(0);
session_start();
include "../db/connect.php";
$password = $_POST['pw'];
$eno = $_POST['eno'];
$password_hash = md5($password);
if(!empty($eno) && !empty($password))
{
$query ="select * from users where eno = '$eno' AND password = '$password_hash'";
$result = $db->query($query);
if($result->num_rows)
{
$_SESSION['login'] = $_POST['eno'];
//echo"<script>alert($_SESSION['login']);</script>"
if(isset($_POST['cb']))
{
setcookie("eno",$eno,time()+3600);
}
echo '1';
}
else
{
setcookie('eno','',time()-3600);
session_regenerate_id();
session_destroy();
echo '';
}
}
else
{
session_regenerate_id();
session_destroy();
}
?>
答案 0 :(得分:0)
没有什么看起来很明显错误,但你的$ _cookie应该是$ _COOKIE
session_start();
if(isset($_COOKIE['eno']))
{
header('location:profile.php');
exit();
}
希望就是这样。