Forum Moderators: coopster

Message Too Old, No Replies

Session / Cookie login problem

         

poobaloo

3:57 am on Nov 2, 2007 (gmt 0)

10+ Year Member



Hi folks,
Have this problem:

Created a nice login form. The form sits in frame "left".

When a user logs in, it sets a session, and if you then click anything in the left frame, targets open in the right, and everything works great. The login info is passed via session.

Now in this login page we have a save cookie setter to save their login to a cookie, for future returns to the page (optional).

If they save their login, the cookie gets written (great!)

When you close browser, and re-open, and return to site, the cookie gets pulled, and the user gets logged in, including redirecting index-l to index-l2 (because l2 is the logged-in page).

HOWEVER...

If you click anything on the left pane (INDEX-L2), to open it in the right, it is not opening a logged in page. (note even removing the target so that it opens in own frame does not help, so it's not a framing issue)

BUT...

If you come to the page (it loads your cookie, redirects you to INDEX-L2)

Then you click REFRESH at the top of the screen--

then you can click anything you like, and the whole session is set fine. Everything works great if you do a simple refresh first.

Can anyone help?

INDEX-L contains this to log people in:
*******************************************************************
function login($fnLoginID, $fnPassword, $fnRememberMe) {
$sql_users = "SELECT * FROM members WHERE id = '$fnLoginID' and mem_pw = '$fnPassword'";
$result_users = mysql_query($sql_users) or die('Query failed');
if (mysql_num_rows($result_users)>0)
{
session_regenerate_id();

$myuser = mysql_fetch_array($result_users);
if ($myuser['is_basic'] == 1) {
$_SESSION['basic_is_logged_in'] = true;
}
if ($myuser['is_admin'] == 1) {
$_SESSION['admin_is_logged_in'] = true;
}

$_SESSION['login_id'] = "$fnLoginID";

$inTwoMonths = 60 * 60 * 24 * 60 + time();
if(isset($_COOKIE['lastLogin'])) {
$_SESSION['visit'] = $_COOKIE['lastLogin'];}
else {
$_SESSION['visit'] = "over 2 mo ago";}

session_write_close();

setcookie(lastLogin, date("G:i - m/d/y"), $inTwoMonths);
if ($fnRememberMe == 1){
setcookie(login_id, $fnLoginID, $inTwoMonths);
setcookie(password, $fnPassword, $inTwoMonths);
}
header('Location: index-l2.php');
exit;
} else {
return 'Invalid login';
}
}

if(isset($_COOKIE['login_id']) && isset($_COOKIE['password'])) {
$login_id=$_COOKIE['login_id'];
$md5_pw=$_COOKIE['password'];
login($login_id, $md5_pw, 0);
}

********************************************************************

INDEX-L2 (the "logged-in" page includes a lot of links, based on checking the SESSIONS "basic_is_logged_in" and so on.

However, none of it works upon revisiting the site, until you click Refresh once! Very baffling, cuz if you enter your login name and password (which calls the same login function above as the cookie check does) then you can click thru anything immediately after.

Thoughts?
-mike

PHP_Chimp

10:35 am on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There does seem to be a few problems with the session_regenerate_id function. So it may be worth commenting that out and trying again.
As I had a similar problem when using that function.

poobaloo

10:13 pm on Nov 5, 2007 (gmt 0)

10+ Year Member



I have tried it both with and without this option. In fact it was originally without, I tried adding that bit as a failed attempt to resolve it.

PHP_Chimp

10:33 pm on Nov 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you post the code without the session_regenerate_id functions in there.
So we can have a look at it.

Habtom

7:31 am on Nov 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think, the reason is that your frames are also having their own Session IDs. Can you use completely cookies or pass the PHPSESSIONID in this mannger PHPSESSIONID=16324552134 to the frames.

Habtom