Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cookie re-setting issue

Status
Not open for further replies.

m3rajk

Programmer
Joined
Sep 2, 2003
Messages
1
Location
US
i have an in issue with my login script. what's happening is that the way it's working, it's causing the user to be logged out immediately after a successful login. i don't know how to fix this.for some reason the nav bar, which changes based on if you're logged in or out, is showing that one is logged out when loading the login success page. the next page shows the logged in nav bar, and the pageload after one is back to being logged out (showing in the nav bar)


i don't understand what's causing the logout to occur so fast since it's not time dependant. i've added (and since removed) a number of debugging lines thinking it was the expiration time on the cookies, but it's not. that's being done right. for some reason it's getting reset.

since the functions that are involved are varoius and mant, i'm showing the one i think is the most likly culprit below, with a link to a page with just the full functions used and the login script below that.


php code:
---------
if($_COOKIE['login']){ # we're logged in
$db=mysql_connect($host, $login2, $pass2) or die("cannot access mysql"); # get the sql connection
$fyd=mysql_select_db('findyourdesire', $db) or die("cannot connect to db"); # select the db
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; # what we wont change on-the-fly
$fprefs=mysql_query("SELECT uid, gmt_offset, tds, login_duration, msgs FROM users WHERE username='$un' AND password='$pw'", $db); # get the prefs
if(mysql_num_rows($fprefs)>0){ # we can update the cookies
$prefs=mysql_fetch_array($fprefs); $gmto=$prefs['gmt_offset']; $utds=$tds[$prefs['tds']];
$duration=$durr[$prefs['login_duration']]; $accepts=($prefs['msgs']*1); $uid=$prefs['uid'];
$expire=(time()+($duration*60));
setcookie('un', $un, $expire); # set username
setcookie('pw', $pass, $expire); # set password
setcookie('login', 1, $expire); # set login
setcookie('gmto', $gmto, $expire); # set the gmt offset
setcookie('utds', $rtds, $expire); # set the time display style
$active=gmdate("Y-m-d H:i:s", time());
$update=mysql_query("UPDATE users SET last_activity='$active' WHERE username='$un'", $db); # try to update users (we don't really care if it fails)
if($accepts){ # person accepts ims
if($accepts>5){ # the user wants them ALL
$fims=mysql_query("SELECT msg_id FROM msgs WHERE to_id='$uid' AND viewed='0'", $db);
$amtims=mysql_num_rows($fims);
if($amtims){ # we have ims
for($i=0;$i<$amtims;$i++){ # for each im
$gimid=mysql_fetch_array($fims); $ims=$gimid['msg_id']; # record the msg_id
}
}
}else{ # user wants $accepts amount
$fims=mysql_query(&quot;SELECT msg_id FROM msgs WHERE to_id='$uid' AND viewed='0' ORDER BY msg_id ASC LIMIT $accepts&quot;, $db);
$amtims=mysql_num_rows($fims);
if($amtims){ # we have ims
for($i=0;$i<$amtims;$i++){ # for each im
$gimid=mysql_fetch_array($fims); $ims=$gimid['msg_id']; # record the msg_id
}
}
}
}
}//else{ cookies('logout'); } # there was an error for some reason
} # end cookie updating



----------------
end of php code

i think else, which is there to make sure those cookies get cleared out incase you have cookies with those names from other sites, is being called no matter what, but i'm not sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top