?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Session Destroy Failure
Author:??(---.bbd06tcl.dsl.pol.co.uk)
Date:???06-02-03 12:03

The following login / logout sequence of code started giving me a session destroy failure out of nowhere - can someone please advise what is the fault in this code?


function login($login) {
global $user_timeout;
$sql = "SELECT count(*) FROM sessions WHERE user='$login' AND login>DATE_SUB(NOW(),INTERVAL ".$user_timeout." MINUTE)";
$result = mysql_query($sql);
if(mysql_error()) echo $sql."
\n".mysql_error();
list($has_login) = mysql_fetch_array($result);

if(!$has_login) {
$_SESSION["user"] = $login;
$sql = "INSERT INTO sessions SET id='".session_id()."',user='".$_SESSION["user"]."'";
mysql_query($sql);
if(mysql_error()) echo $sql."
\n".mysql_error();

$sql = "INSERT INTO chat SET text='<".$_SESSION["user"]." entered>',user='".$_SESSION["user"]."',time=NOW()";
mysql_query($sql);
if(mysql_error()) echo $sql."\n
".mysql_error();
} else {
return "This nickname is already taken.";
}
}

function logout() {
global $user_timeout;
if($_SESSION["user"]) {
session_start();
$sql = "INSERT INTO chat SET text='<".$_SESSION["user"]." left>',user='".$_SESSION["user"]."',time=NOW()";
mysql_query($sql);
if(mysql_error()) echo $sql."\n
".mysql_error();
}

$sql = "DELETE FROM sessions WHERE id='".session_id()."'";
mysql_query($sql);
if(mysql_error()) echo $sql."
\n".mysql_error();

$sql = "DELETE FROM sessions WHERE login mysql_query($sql);
if(mysql_error()) echo $sql."
\n".mysql_error();
$_SESSION["user"] = false;
session_destroy();

}

Thanks in advance.

Regards, Ivan

?Topics Author? Date
?Session Destroy Failure??new
Ivan the Naib 06-02-03 12:03?
?Re: Session Destroy Failure??new
federico 06-02-03 13:19?
?Re: Session Destroy Failure??new
Ivan the Naib 06-02-03 14:16?
?Re: Session Destroy Failure??new
federico 06-02-03 19:26?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > The following login / logout sequence of code started giving > me a session destroy failure out of nowhere - can someone > please advise what is the fault in this code? > > > function login($login) { > global $user_timeout; > $sql = "SELECT count(*) FROM sessions WHERE user='$login' > AND login>DATE_SUB(NOW(),INTERVAL ".$user_timeout." MINUTE)"; > $result = mysql_query($sql); > if(mysql_error()) echo $sql."
\n".mysql_error(); > list($has_login) = mysql_fetch_array($result); > > if(!$has_login) { > $_SESSION["user"] = $login; > $sql = "INSERT INTO sessions SET > id='".session_id()."',user='".$_SESSION["user"]."'"; > mysql_query($sql); > if(mysql_error()) echo $sql."
\n".mysql_error(); > > $sql = "INSERT INTO chat SET text='<".$_SESSION["user"]." > entered>',user='".$_SESSION["user"]."',time=NOW()"; > mysql_query($sql); > if(mysql_error()) echo $sql."\n
".mysql_error(); > } else { > return "This nickname is already taken."; > } > } > > function logout() { > global $user_timeout; > if($_SESSION["user"]) { > session_start(); > $sql = "INSERT INTO chat SET text='<".$_SESSION["user"]." > left>',user='".$_SESSION["user"]."',time=NOW()"; > mysql_query($sql); > if(mysql_error()) echo $sql."\n
".mysql_error(); > } > > $sql = "DELETE FROM sessions WHERE id='".session_id()."'"; > mysql_query($sql); > if(mysql_error()) echo $sql."
\n".mysql_error(); > > $sql = "DELETE FROM sessions WHERE > login mysql_query($sql); > if(mysql_error()) echo $sql."
\n".mysql_error(); > $_SESSION["user"] = false; > session_destroy(); > > } > > Thanks in advance. > > Regards, Ivan ">??

Provided By
Phorum