$_SESSION variable not passing and no clue why? it sets then doesn't pass

前端 未结 4 870
无人共我
无人共我 2021-01-26 17:53

I have a login script coded in php and mysqli. upon submission and successful authentication it redirects to success.php to write sessions. my success page looks like this.

相关标签:
4条回答
  • 2021-01-26 18:10

    Adding to answers, If you don't want to write session_start() on starting of each and every page, You can simply skip it by setting the session.auto_start = 1 in your php.ini file , which starts the session automatically on request page. Refer to PHP Session Configuration Documentation.

    0 讨论(0)
  • 2021-01-26 18:20

    The initial file didn't contain session_start() as pointed out. however it works without it for some reason now.

    I am thinking a cache or server delay issue also

    0 讨论(0)
  • 2021-01-26 18:21

    Use session_start(); inside all page before using $_SESSION variable in PHP. session_start(); function use to initialize session process.

    your success.php should be.

    <?php  
    /**
     * Set cookies here if/as needed.
     * Set session data as needed. DO NOT store user's password in
     * cookies or sessions!
     * Redirect the user if/as required.
     */
    
     session_start();
    
     $id = $_GET['id'];
    
    $_SESSION['partner_id']       = $id;
    $_SESSION['authenticated'] = TRUE;
    
    if (isset($_SESSION['partner_id'])) {
    echo("<script>
    <!--
    location.replace(index.php);
    -->
    </script>");
    
    }
    
    else {
        print "Session partner id not set";
    }
    
    ?>
    
    0 讨论(0)
  • 2021-01-26 18:33

    You need session_start() on all pages using $_SESSION

      <?php  
     /**
     * Set cookies here if/as needed.
     * Set session data as needed. DO NOT store user's password in
     * cookies or sessions!
     * Redirect the user if/as required.
     */
     session_start();
    
     $id = $_GET['id'];
    
    $_SESSION['partner_id']       = $id;
    $_SESSION['authenticated'] = TRUE;
    

    Also...are you sure that $_GET['id'] has a value in it?

    And....is your form using POST or GET?

    Ive made that silly mistake before , where form was using POST and I was retrieving variable with GET and getting frustrated. Just a possibility

    0 讨论(0)
提交回复
热议问题