Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Location
    In a box, US
    Posts
    306
    Tokens
    0

    Default PHP Sessions help...

    Okay... so... The sessions are not staying when a user logs in...

    here's my "login.php"

    PHP Code:
    <? session_start();
    include(
    'database.php');
        require 
    "functions.all.php";
    if(!isset(
    $_SESSION['loggedin'])){
                if(!isset(
    $_POST['loginOK'])){
                        
    displayLoginForm();
                         
    //Probably gonna call a display class here
                      
    }else{
     
         
                            
    processLogin();
                                

    }
             }else{  echo 
    "Hello, ".$_SESSION[user].". And welcome to the user system."; }
               
    ?>
    here is the 2 functions....
    PHP Code:
    function displayLoginForm()
    {
       echo 
    '<div style="padding-left: 5px;">
        

    <form method="post" name="loginForm" onsubmit="myHabbio.__doLogin();return false;"> 
      <b>Username:</b><br /> <input type="text" name="username" id="username" class="oo" /><br />
      <b>Password:</b><br /> <input type="password" name="password" id="password" class="oo" /><br />
      
       <input type="submit" id="loginOK" style="margin-top:3px;" value="Login &raquo;" name="sOK" onclick="myHabbio.__doLogin();return false;" class="oo" /> or FB_connect()<br />
       No account? <a href="my1/register.php">Register for free!</a>
    </form>
    </div>
    '
    ;


    }


    //////////////////////


    function processLogin() {
    $username $_POST['username'];
    $password sha1($_POST[password]);
    $exsists mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `username`='" $username "'"));
                   if(
    $exsists == 0){ throwLoginError('Incorrect username/password</b><br />Please try again'); }
                      else{  
    $result mysql_query("SELECT * FROM users
                                         WHERE username='
    $username'") or die();  
                                            
    $row mysql_fetch_array$result );
                                                  
    $password1 sha1($row[password]);
                                                  if(
    $password == $password1){ $_SESSION['user'] = $username$_SESSION['loggedin'] == 1
    //I have ^^ The sessions set there... but when the user reloads the page, it displays the login form =/
    displayUserBox();

     }else{ 
    throwLoginError('Incorrect username/password</b><br />Please try again'); }
                                  }




    When a user logs in; i have it set the sessions and display the "userbox".... but when I refresh the page, the login form is displayed... even though the seesions were already set. HELP :/
    PureHosts.com
    Shared, ShoutCAST, and reseller hosting.
    Reasonable prices, amazing support.

    Views expressed by me through my HXF, CHF or any forum account, do not necessarily express the views or opinions of Pure Web Solutions.

  2. #2
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default

    Looking at the code this is for a retro then? or am i wrong?

  3. #3
    Join Date
    Oct 2008
    Location
    In a box, US
    Posts
    306
    Tokens
    0

    Default

    No? It's for a fansite if you have to know.
    PureHosts.com
    Shared, ShoutCAST, and reseller hosting.
    Reasonable prices, amazing support.

    Views expressed by me through my HXF, CHF or any forum account, do not necessarily express the views or opinions of Pure Web Solutions.

  4. #4
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Do you have session_start(); in the file with the functions as well? I think you need to global it as well but I'm not sure as I've never tried to set a session within a function.

    ---------- Post added 03-09-2010 at 11:40 AM ----------

    disregard above,

    $_SESSION['loggedin'] == 1

    should be 1 =
    Last edited by Trigs; 03-09-2010 at 03:35 PM.
    Vouches
    [x][x]

  5. #5
    Join Date
    Oct 2008
    Location
    In a box, US
    Posts
    306
    Tokens
    0

    Default

    ^^Thank you [: that worked
    PureHosts.com
    Shared, ShoutCAST, and reseller hosting.
    Reasonable prices, amazing support.

    Views expressed by me through my HXF, CHF or any forum account, do not necessarily express the views or opinions of Pure Web Solutions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •