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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?