Hi all,I have a problem with a website that uses php login with cookies... when some one tries to log in it returns nothing and you have to keep trying about 2-4 times this is very random and some times it will let you login without a problem...This happens in all browsers and all platforms
//////////////////////check login script
<?php
if(isset($_COOKIE["nano"]["userID"])&&isset($_COOKIE["nano"]["uniqueID"])){
$db = mysql_connect("localhost","om_dba","pass");
mysql_select_db("om",$db);
$query = sprintf(
"select CookieID
from Cookies
where UserID = %s and UniqueID = '%s'",
mysql_real_escape_string($_COOKIE["nano"]["userID"]),
mysql_real_escape_string($_COOKIE["nano"]["uniqueID"]));
$result = mysql_query($query);
if(mysql_num_rows($result) == 1){
$query = sprintf(
"select t.Type, t.TypeID
from Users u
join UserTypes t on u.UserType = t.TypeID
where
u.UserID = %s",
mysql_real_escape_string($_COOKIE["nano"]["userID"]));
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
session_start();
session_name("om");
$_SESSION['userID'] = $_COOKIE['nano']['userID'];
$_SESSION['userType'] = $row['Type'];
$_SESSION['userTypeID'] = $row['TypeID'];
$query = sprintf(
"update Users
set DateLastLoggedIn = curdate()
where UserID = '%s'",
mysql_real_escape_string($_COOKIE['nano']['userID']));
mysql_query($query);
unset($query,$result,$row);
} else {
setcookie("PHPSESSID","",time()-3600);
setcookie("nano[userID]","",time()-3600);
setcookie("nano[uniqueID]","",time()-3600);
}
}
?>
////////////////
Thanks!
//////////////////////check login script
<?php
if(isset($_COOKIE["nano"]["userID"])&&isset($_COOKIE["nano"]["uniqueID"])){
$db = mysql_connect("localhost","om_dba","pass");
mysql_select_db("om",$db);
$query = sprintf(
"select CookieID
from Cookies
where UserID = %s and UniqueID = '%s'",
mysql_real_escape_string($_COOKIE["nano"]["userID"]),
mysql_real_escape_string($_COOKIE["nano"]["uniqueID"]));
$result = mysql_query($query);
if(mysql_num_rows($result) == 1){
$query = sprintf(
"select t.Type, t.TypeID
from Users u
join UserTypes t on u.UserType = t.TypeID
where
u.UserID = %s",
mysql_real_escape_string($_COOKIE["nano"]["userID"]));
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
session_start();
session_name("om");
$_SESSION['userID'] = $_COOKIE['nano']['userID'];
$_SESSION['userType'] = $row['Type'];
$_SESSION['userTypeID'] = $row['TypeID'];
$query = sprintf(
"update Users
set DateLastLoggedIn = curdate()
where UserID = '%s'",
mysql_real_escape_string($_COOKIE['nano']['userID']));
mysql_query($query);
unset($query,$result,$row);
} else {
setcookie("PHPSESSID","",time()-3600);
setcookie("nano[userID]","",time()-3600);
setcookie("nano[uniqueID]","",time()-3600);
}
}
?>
////////////////
Thanks!