Tôi có một mã đăng nhập qua AJAX và sau đó chuyển dữ liệu đến tệp .php để kiểm tra nó dựa trên SQL. cho một thử nghiệm, tên người dùng và mật khẩu là tôi - tôi tuy nhiên ngay cả tho này trở lại từ kiểm tra nó không đăng nhập tôi, có vẻ như phiên họp không được thiết lập.Phiên PHP không được thiết lập
log.php
<script type="text/javascript">
$(document).ready(function()
{
$("#login_form").submit(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
//check the username exists or not from ajax
$.post("ejaxlog.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
{
if($.trim(data)=='yes') //if correct login detail
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
function()
{
//redirect to secure page
document.location='http://www.google.com';
});
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
});
}
});
return false; //not to post the form physically
});
//now call the ajax also focus move from
$("#password").blur(function()
{
$("#login_form").trigger('submit');
});
});
</script>
<link type="text/css" href="formboxes.css" rel="stylesheet">
</head>
<body>
<?
echo $_SESSION['u_name'];?>
<form method="post" action="" id="login_form">
<div align="center">
<div >
User Name : <input name="username" type="text" id="username" value="" maxlength="20" />
</div>
<div style="margin-top:5px" >
Password :
<input name="password" type="password" id="password" value="" maxlength="20" />
</div>
<div class="buttondiv">
<input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:23px" /> <span id="msgbox" style="display:none"></span>
</div>
</div>
</form>
này sau đó kiểm tra MySQL thông qua mã kế tiếp, là nó là thành công nó Echos ra "có" mà tôi nhìn thấy trong tiêu đề HTTP của tôi (vì vậy phải đúng) nhưng nó không chuyển hướng tôi đến "eindex.php" như được chỉ định trong tệp log.php.
<?php
session_start();
require("../mcfrdb.php");
// Included database once using the require method
?>
<?php
$username = mysql_real_escape_string(stripslashes($_POST['username']));
$pass = mysql_real_escape_string(stripslashes($_POST['password']));
$result = mysql_query("SELECT user, pass FROM mcfruse WHERE user='$username'")or die(mysql_error());
$row=mysql_fetch_array($result);
if(mysql_num_rows($result)>0)
{
if(strcmp($row['pass'],$pass)==0)
{
echo "yes";
$_SESSION['name']=$username;
}
else
echo "no";
}
else
echo "no";
HTML của tôi khi sử dụng firebug nói
có
nên có được echo'ed có nghĩa là nó đi bên phải pwd và nó xác nhận, nhưng nó vẫn nói "chi tiết đăng nhập sucks" và doesnt chuyển hướng tôi đến eindex.php
eindex.php
<?php
session_start();
if(!isset($_SESSION['name']))
header("Location:../index.php");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:../index.php");
}
require("../mcfrdb.php");
?>
Tôi đã kiểm tra mã này một vài lần nhưng không thể tìm thấy bất kỳ thứ gì. Tất cả các câu trả lời và bất kỳ trợ giúp được đánh giá cao. Rất cám ơn.
EDIT: thậm chí thêm vào md5 pwd băm (bỏ qua từ mã này) tôi vẫn nhận được "có" và khi tôi echo tên người dùng và băm, họ là bot phù hợp, phiên không được đặt vẫn tuy nhiên và không chuyển hướng tôi. trên if ($. trim (dữ liệu) == 'yes')
[session_start() '] của bạn ở đâu (http://php.net/manual/en/function.session-start.php)? – feeela
Thông báo lỗi tuyệt vời bro –
đó là trong đó, jsut trên dòng đầu, mã bỏ qua fro mthe của nó, tôi đoán tôi nên có bị mắc kẹt trong; D – ben