Sessions don't work. Help

Discussion in 'PHP' started by fear, Apr 28, 2009.

  1. #1
    Hello everyone,
    I've created a login page, where you enter your username and password, it checks the database and if it matches then you go to another page else you will get a Wrong username or password error.
    I've got three files
    login.php
    check_login.php
    login_success.php

    You enter username and password in login.php and it goes to check_login.php and validates it if it is correct you will go to login_success.php else you will get the error.
    I can't go directly to check_login.php because I will get error but if directly go to login_sucess.php I don't get the error, although here is the code I have in it.
    I'm supposed to get redirected to login.php but instead I see login successful.
    Here is the code I have in check_login.php

    That is not the full but it is for registering the sessions.
    Any info what do I do with this?

    Regards,
     
    fear, Apr 28, 2009 IP
  2. fear

    fear Banned

    Messages:
    3,750
    Likes Received:
    221
    Best Answers:
    0
    Trophy Points:
    205
    #2
    Also tried these things
    And
    None works
     
    fear, Apr 28, 2009 IP
  3. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    pixmania, Apr 28, 2009 IP
  4. Steve136

    Steve136 Peon

    Messages:
    240
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    I've just re-wrote it and tested it on PHP5 - This should work.

    
    <?php
    if(!isset($_SESSION['username'])) {
           header("Location: login.php");
    } else {
    ?>
    <html>
          <body>
                Login Successful
          </body>
    </html>
    <?php } ?>
    
    Code (markup):
    There shouldn't be a need for session_start(); in the login check because if the user has logged in the session will already be set.
     
    Steve136, Apr 28, 2009 IP
  5. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need the session_start or else the session is lost.

    Try this for login_success
    
    <?php
    session_start();
    if (session_is_registered(username))
    {
    echo '<html><body>Login Successful!</html></body';
    }
    else
    {
    header("Location: login.php");
    }
    ?>
    
    Code (markup):
     
    SHOwnsYou, Apr 28, 2009 IP
  6. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #6
    huff...

    i think guys in here has reply good answer for u .. n it's should be work :)

    regards
     
    ghprod, Apr 28, 2009 IP
  7. usadesi

    usadesi Peon

    Messages:
    296
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for information....
     
    usadesi, Apr 28, 2009 IP