Jump to content

session trouble


doddsey_65

Recommended Posts

in my login script i have the following which searches for the username they inputted and then adds their user id to the table sessions in the database.

 

$result = mysql_query("SELECT * FROM ".DB_PREFIX."members WHERE user_username = '$username' AND user_password = '$password'");
        
            if(mysql_num_rows($result) != 1)
            {
                $val_error = 'Username and Password incorrect.';
            }
                else
                {
                 $row = mysql_fetch_array($result);
                    $browser = $_SERVER['HTTP_USER_AGENT'];
                    $_SESSION['user_id'] = $row['user_id'];
                    $_SESSION['session'] = session_id();
                    mysql_query("INSERT INTO ".DB_PREFIX."sessions 
                    VALUES(NULL, '".$_SESSION['user_id']."', '".$_SESSION['session']."', '".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['HTTP_USER_AGENT']."', '".date('Y-m-d')."')");
                    
                    if ($_SESSION['backpage']) 
                    {
                    header('Location: '.$_SESSION['backpage']);
                    } else {
                    
                    header('Location: index.php');
                    }
                }

 

then on pages which i want only logged in members to access i have the following:

 

if ($_SESSION['user_id'] == '') {
header ('Location: '.SITE_ROOT.'/login.php');
} else { REST OF CODE }

 

but when i login and try to access a page which requires you to be logged in i am directed back to index.php. I have nothing which does that. if you are not logged in you are redirected to login.php but it doesnt seem to work.

Any ideas?

 

Link to comment
Share on other sites

You need to see what the value of $_SESSION['backpage'] is before using a clause on it, it could well be empty, so check that BEFORE you get to that if clause, and check that the sql that you are using is populated as expected by echoing it to screen.

 

This sound like a case of debugging to me, but ya never know!

 

Rw

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.