我遇到$ _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)上运行。
注意:我不编码密码,因为我只是在进行基本测试而几乎没有失败!
EDIT:
为会话分配ID后,该会话不会保存到index.php,因为如果我执行var_dump($ _ SESSION)或回显$ _SESSION [“ ID”],我什么也收不到,但是,如果我用登录脚本中的数据进行响应,而用echo 1
代替,我将获得echo $_SESSION["ID"]
,则我得到了会话/ ID,但是它并没有以某种方式转移到index.php页面!我在$ _SESSION中遇到问题,我将粘贴代码并进行解释。我有一个包含
$_SESSSION['ID'] = $credentials['userID'];
应该是:
$_SESSION['ID'] = $credentials['userID'];
您有一个额外的S