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条)

报告相同问题?

悬赏问题

  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃