Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts

    session not working!

    PHP Code:

    <?php
    session_start
    ();
    if (
    $_SESSION['loggedin'] = 'yessir')
    {
    echo 
    "congratulations you have logged in ";
    } else { 
    header("location: http://rafiki.freehostia.com/register.php");
           }
    ?>
    is the page where you cant reach unless you log in
    heres a bit of the log in page

    PHP Code:
     $sql "SELECT 1 FROM 'users' WHERE 'username' = '$username' AND 'password' = $password";
        
    $query mysql_query($sql) or die(mysql_error());
        if (
    mysql_num_rows($query)>0){
            
    $_SESSION['loggedin'] = yessir;
            
    $_SESSION['username'] = $username;
    header("Location: http://rafiki.freehostia.com/loggedin.php");
    } else {
    unset(
    $_SESSION['loggedin']); 
    but if you visit
    http://rafiki.freehostia.com/loggedin.php it doesnt actually redirect back to register.php

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    if ($_SESSION['loggedin'] == 'yessir'
    Should also put quotes around this, as it's a string (4th line)
    PHP Code:
    $_SESSION['loggedin'] = 'yessir'

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    changed it but still echos you have logged in when i go straight to loggedin.php
    any other ideas

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    It forwards me to register.php.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Quote Originally Posted by rafiki View Post
    changed it but still echos you have logged in when i go straight to loggedin.php
    any other ideas
    Close your browser and retry. You'll have the session set which is why it's showing that page


  •  

    Posting Permissions

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