Click to See Complete Forum and Search --> : how to destroy my session?


brabus
08-19-2003, 01:55 AM
Hi all,
i'm a newbie in php. quite dizzy in solving this session thingy. So, here's my logincheck script -> to check whether user id & password matched. if matched, status will be setted to 1, and u can see what will happen from the code below. i got no problem to login & i can protect all the pages which is need to protected from the other user.


<?php
$status = authenticate($uid, $pwd);

if ($status == 1)
{
session_start();
session_register("SESSION");
session_register("SESSION_UNAME");
$SESSION_UNAME = $uid;
header("Location: main-all2.php");
exit();
}
else
{
header("Location: login1.php");
exit();
}

function authenticate ($user, $pass)
{
$db="MyDatabaseName";

$con=mysql_connect("localhost","","") or die ("no connection");

$qwery="Select * from admin where uid='$user' and pwd='$pass'";
$result=mysql_db_query($db,$qwery,$con) or die ("sql cannot be executed");


if (mysql_num_rows($result) == 1)
{
return 1;
}
else
{
return 0;
}
}
?>


but the problem is, i can't destroy session created in the system. here's my script for logout part;
<?php
session_start();
session_destroy();
header("Location: login1.php");
?>

if i run this script..i'll get this error msg;
Warning: Session object destruction failed in c:\apache\htdocs\capexonlinesystem\logout.php on line 2

so...anybody out there can help me to solve this problem???
tq in advance.

:confused:

rincewind2
08-19-2003, 04:06 AM
To unregister the variables,
use
session_unregister().
Then you can destory the session...

And I dont think you need to use session_start() in your logout script. It's already done in your login script.

Hope this helps.

brabus
08-19-2003, 09:51 PM
i still got an error msg;
'Session object destruction failed' at session_destroy() line.

if i'm not include session_start in my logout script, i'll get this error msg;
'Trying to destroy uninitialized session' at session_destroy() line.

it's always error at session_destroy line.

any solution?? help me please.....:(

pyro
08-19-2003, 11:07 PM
Try:

session_start();
session_unset();
session_destroy();