dongnachuang6635 2017-08-21 05:03
浏览 13
已采纳

如何设置会话ID并在php的下一页上进行验证

I want to set session id using pin column my query result and check to see whether the session was set to that value on the next page, Here is my code

<?php
require_once('AppLogin_Class.php');
$success='';
if(isset($_POST['submit'])){
$pin=$_POST['SIDN'];
$status=0;
try{
        require_once('connection.php');

        $message='Invalid Application Pin';
        $STH=$db_conn->prepare("SELECT * FROM pins WHERE pin=? && status=?");
        $STH->bindParam(1,$pin);
        $STH->bindParam(2,$status);
        $STH->execute();
        $row=$STH->fetch();
        if($STH->rowCount()==1){
            $_SESSION['id']=$row['pin'];;

            echo '<meta http-equiv="refresh" content="=1;applicants/upload_pass.php?pin=$pin"/> ';
        }else{
            return $message;
        }
    }catch(PDOException $e){
        echo $e->getMessage();
    }
}
?>

Here is my next page verification code

<?php
$pin=$_GET['pin'];
require_once('class_applicants.php');
if(!isset($_SESSION['id'])){
echo '<meta http-equiv="refresh" content="=1;../appHome.php"/> ';
}else{
//success page here
}?>

Someone should help me to check while the page is loging me out because of session id

  • 写回答

2条回答 默认 最新

  • duanhuang1967 2017-08-21 05:08
    关注

    Use session_start();

    Example:

    <?php
      session_start();
      $pin=$_GET['pin'];
      require_once('class_applicants.php');
       if(!isset($_SESSION['id'])){
      echo '<meta http-equiv="refresh" content="=1;../appHome.php"/> ';
      }else{
      //success page here
        }?>
    

    and also

    <?php
      session_start();
    require_once('AppLogin_Class.php');
     $success='';
     if(isset($_POST['submit'])){
    $pin=$_POST['SIDN'];
     $status=0;
     try{
        require_once('connection.php');
    
        $message='Invalid Application Pin';
        $STH=$db_conn->prepare("SELECT * FROM pins WHERE pin=? && status=?");
        $STH->bindParam(1,$pin);
        $STH->bindParam(2,$status);
        $STH->execute();
        $row=$STH->fetch();
        if($STH->rowCount()==1){
            $_SESSION['id']=$row['pin'];;
    
            echo '<meta http-equiv="refresh" content="=1;applicants/upload_pass.php?pin=$pin"/> ';
        }else{
            return $message;
        }
    }catch(PDOException $e){
        echo $e->getMessage();
    }
    }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?