2016-09-18 1 views
1

私のlogin_check phpファイルとlogin_done phpファイルです。 セッション関数を入れる前に、うまくいきました。 しかし、私はいくつかのセッション機能を挿入した後、動作を停止し、有効なIDとパスワードであっても "無効なログイン"を引き起こします。phpでセッションを維持するについて

'login_check.php'

<?php 
    session_start(); 
    include_once ('../config.php'); 
    $mysqli = new mysqli($DB['host'], $DB['id'], $DB['pw'], $DB['db']); 
    if (mysqli_connect_error()) { 
     exit('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); 
    } 

    extract($_POST); 

    $q = "SELECT * FROM ap_member WHERE id='$user_id'"; 

    $result = $mysqli->query($q); 

    if($result->num_rows==1) { 
     $encrypted_pass = sha1($user_pass); 
     $row = $result->fetch_array(MYSQLI_ASSOC); 
     if($row['pw'] == $encrypted_pass) { 
      header("Location: http://sovereign-recipe.com/member/login_done.php"); 
      exit(); 
     } 
     else { 
      echo 'wrong password'; 
     } 
    } 
    else { 
     echo 'ID does not exist or invalid approach. Try again.'; 
    } 

    if($row['pw'] == $encrypted_pass) { 
      $_SESSION['is_logged'] = 'YES'; 
      $_SESSION['user_id'] = $user_id; 
      header("Location: http://sovereign-recipe.com/member/login_done.php"); 
      exit(); 
     } 
     else { 
      $_SESSION['is_logged'] = 'NO'; 
      $_SESSION['user_id'] = ''; 
      header("Location: http://sovereign-recipe.com/member/login_done.php"); 
      exit(); 
     } 

?> 

'login_done.php'

<?php 
    session_start(); 
    $is_logged = $_SESSION['is_logged']; 

    if($is_logged=='YES') { 
     $user_id = $_SESSION['user_id']; 
     $message = $user_id . 'login success. session would continue with your logged-in info. start your surf.'; 
    } 
    else { 
     $message = 'your log-in is invalid. please, try again.'; 
    } 

    var_dump($_SESSION); 

?> 

    <html> 
     <head> 
      <title>login result</title> 
      <meta charset="utf-8" > 
     </head> 
     <body> 

    <?php 
     echo $message; 
    ?> 

    </body> 
</html> 

enter image description here

+0

IDとパスワードが渡されたかどうかをデバッグしてみてください。 –

+0

どのようにデバッグチェックを行うには、それのための良いリファレンスガイドはありますか? –

+0

あなたのクエリは、SELECT * FRAM ap_member WHERE id = '$ user_id'とpassword = '' $ encrypted_pa​​ss "であり、このクエリの後にnum_rows()をチェックする必要があります。 – Bhavin

答えて

0

あなたlogin_check.phpにこの方法を試してみてください

session_start(); 
include_once ('../config.php'); 
$mysqli = new mysqli($DB['host'], $DB['id'], $DB['pw'], $DB['db']); 
if (mysqli_connect_error()) { 
    exit('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); 
} 

extract($_POST); 

$q = "SELECT * FROM ap_member WHERE id='$user_id'"; 

$result = $mysqli->query($q); 

if ($result->num_rows == 1) { 
    $encrypted_pass = sha1($user_pass); 
    $row = $result->fetch_array(MYSQLI_ASSOC); 
    if ($row['pw'] == $encrypted_pass) { 
     $_SESSION['is_logged'] = 'YES'; 
     $_SESSION['user_id'] = $user_id; 
    } else { 
     $_SESSION['is_logged'] = 'NO'; 
     $_SESSION['user_id'] = ''; 
     //echo 'wrong password'; 
    } 
} else { 
    $_SESSION['is_logged'] = 'NO'; 
    $_SESSION['user_id'] = ''; 
    echo 'ID does not exist or invalid approach. Try again.'; 
} 

//You can to use here your redirect, then remove the previous 
header("Location: http://sovereign-recipe.com/member/login_done.php"); 
exit(); 

Iホこれはあなたに役立ちます。

関連する問題