Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Getting error for using the session variables used in PHP

    • 0
    • 0
    • 0
    • 3
    • 0
    • 0
    • 0
    • 421
    Answer it
    <?php
    session_start();
    
    include_once('config.php');
    $user=htmlentities(stripslashes($_POST['username']));
    $password=htmlentities(stripslashes($_POST['password']));
    // Some query processing on database    
    
    if(($id_user_fetched<=$id_max_fetched) && ($id_user_fetched!=0)){
    $_ESSION['loggedIn'] = 'yes';
        header("Location:http://abc/inbox.php?u=$id_user_fetched");
        //echo 'Login Successful';
        }else{
            echo 'Invalid Login';
            echo'<br /> <a href="index.html">Click here to try again</a>';
            }
    }else{
        echo mysqli_error("Login Credentials Incorrect!");
        }
    ?>
    

    And my index.php page code is as follows:-

    <?php
    session_start(); 
    echo 'SESSION ='.$_SESSION['loggedIn'];
    if($_SESSION['loggedIn'] != 'yes'){
    echo $message = 'you must log in to see this page.';
    //header('location:login.php');
    }
     //REST OF THE CODE
    
    ?>
    

    Everytime the above code execute, my page inbox.php is giving the output:-

    SESSION=you must log in to see this page.
    

    Please comment and tell me where i'm doing the wrong step?

 3 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: