2015-10-16 67 views
-2

我遇到$ _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我們有這個(縮短的版本,是的,我已經在session_start()在index.php文件的開頭):

<?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上運行XAMPP(本地主機)10

注意:我不編碼的密碼,因爲我只是做基本的測試中,我幾乎failling!

編輯: attrbuiting的ID到會議結束後,會議不會保存到的index.php,因爲如果我做的var_dump($ _ SESSION)或echo $ _SESSION [ 「ID」]我收到什麼,但如果我使用登錄腳本中的數據進行響應,而不是echo 1,我會有echo $_SESSION["ID"],那麼我將獲得會話/ ID,但它不會以某種方式傳輸到index.php頁面!

+0

您添加了很多代碼,但沒有描述實際問題。 – GolezTrol

+0

你能詳細說明這個問題嗎? – Crackertastic

+0

是您的查詢返回用戶? – taxicala

回答

3

你有一個錯字,檢查它是否只有在這裏你的問題的代碼或在您的實際代碼,以及:

$_SESSSION['ID'] = $credentials['userID']; 

應該是:

$_SESSION['ID'] = $credentials['userID']; 

你有一個額外S

+0

實際上是這樣!我不能相信我已經錯過了:( 我一直在這個像4小時左右,我的眼睛正在燃燒!!! 謝謝! – Sashka

+0

沒問題。很高興幫助:) – taxicala