why session variable is empty to navigate the next page?

前端 未结 1 1601
天命终不由人
天命终不由人 2021-01-29 05:49

I have been working is a website I have been dealing with a problem from a while, and now I know why it is happening, but not how to solve it. Please help!!

Page 1: In

相关标签:
1条回答
  • 2021-01-29 06:22

    use session in the start in first page, like this. Hopefully this will work

     <?php
    session_start(); 
    if (isset($_POST['sub'])) 
    {
                $user=$_POST['user'];
                $pass=$_POST['pass'];
                $con=mysqli_connect("localhost","root","");
                $db=mysqli_select_db($con,"Database");
                $qry="select * from TABLE where username='$user' and password='$pass'";
                $res=mysqli_query($con,$qry)or die("could not connect to mysql");
                $row=mysqli_fetch_array($res);
                $len=mysqli_num_rows($res);
                if($len<=0)
                 {
                   echo"<script>";
                   echo"alert('Oops.Username Or Password Incorrect!');window.location.href='login.php';";
                   echo"</script>";
                }
               else
                {
    
            $_SESSION['id']=$row['id'];
            $_SESSION['message']=$user;
            $_SESSION['logout']="";
            $id=$_SESSION['id'];
            echo"<script>"; 
            echo"alert('log in Success $id ');window.location.href='login.php';"; //$id is print correctly 
            echo"</script>";
            }
        }
    
    ?>
    
    0 讨论(0)
提交回复
热议问题