[英]PHP $_SESSION issue
我遇到了 $_SESSION 的問題,我將粘貼代碼並進行解釋。
我有一個索引,其中包括
<div class="confidential__field text-align-center">
<table>
<tbody>
<tr>
<td><label for="email">Email</label></td>
<td><input type="text" id="email" name="email"></input></td>
</tr>
<tr>
<td><label for="pwd">password</label></td>
<td><input type="password" id="pwd" name="pwd"></input></td>
</tr>
<tr>
<td><a href="?action=register">Don't have an account ?</a></td>
<td><button form="form" id="login">Send</button></td>
</tr>
</tbody>
</table>
</div>
index.php 我們有這個(縮短版本,是的,我在 index.php 的開頭有 session_start()):
<?php
session_start();
include("_include/_stuff/config.php");?>
<!doctype html>
<html>
<?php include("_general/head.php");?>
<body>
<?php
include("_include/login.php");
if(isset($_SESSION['ID']) && !empty($_SESSION['ID']))include("_include/header.php");
?>
</body>
</html>
然后是腳本:
$(document).ready(function(){
$("#login").click(function(){
$.post("_ajax/clientMain.php",{
login: 1,
email: $("input#email").val(),
pwd: $("input#pwd").val()
},
function(data){
if(data==1){
//alert(data);
// alert("SESSION SET");
location="index.php";
}else{
alert(data);
}
}
)
});
});
然后要檢查實際的php:
session_start();
if(isset($_POST['login']) && !empty($_POST['login'])){
$conn = db_connect();
$email = db_quote($_POST['email']);
$pwd = db_quote($_POST['pwd']);
$query_attendance = mysqli_query($conn, "select * from user where email=$email and password=$pwd");
if(mysqli_num_rows($query_attendance) > 0){
$credentials = mysqli_fetch_array($query_attendance, MYSQLI_ASSOC);
if(!empty($credentials)){
$_SESSSION['ID'] = $credentials['userID'];
echo 1;
}else{
echo 82;
}
}else{
echo 45;
}
}else{
echo 111;
}
我在 Windows 10 上的 XAMPP(localhost) 上運行。
注意:我沒有對密碼進行編碼,因為我只是在進行基本測試,我幾乎不會失敗!
編輯:將 ID 賦予會話后,會話不會保存到 index.php,因為如果我執行 var_dump($_SESSION) 或 echo $_SESSION["ID"] 我什么也沒有收到,但是如果我用數據響應在登錄腳本中,而不是echo 1
我會得到echo $_SESSION["ID"]
然后我得到會話/ID,但它沒有以某種方式傳輸到 index.php 頁面!
您有一個錯字,請檢查它是否僅出現在您的問題代碼中或您的實際代碼中:
$_SESSSION['ID'] = $credentials['userID'];
應該:
$_SESSION['ID'] = $credentials['userID'];
你有一個額外的S
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.