Page 1 of 1

session_destroy as logout

Posted: Fri Mar 03, 2006 8:34 am
by duk
hy guys..

i use session_destroy for a logout script... and i use logout.php and then redirects to index.php

if im in a form.php and i apply a logout it doesn't unset all sessions in form.php if a return to form.php will have all sessions as normal this is normal...

how can i resolve this ??

Posted: Fri Mar 03, 2006 8:40 am
by feyd
I think your issue is code specific.. show some.

Posted: Fri Mar 03, 2006 8:44 am
by duk
humm

ok my logou.php located at "/"

Code: Select all

setcookie("CINTRA", $_COOKIE['CINTRA'], time()-5184000);
session_destroy();
//ob_end_flush();
header("location: /");
but i have a form.php in /forms/apf/form.php where for example its stores $_SESSIONS as user going to page1, page2 when finish it produces a session_destroy in form.php...

but if i for example in page2 i decide to click logout, executes /logout.php and then redirects to index.php located at main dir "/" if i return to my /forms/apf/form.php my forms still have my $_SESSIONS as previous posted...

Posted: Fri Mar 03, 2006 8:47 am
by feyd
Using header redirection can short circuit the transmission of any other headers, often does. Call session_write_close() before calling header(), which should fix it.

Posted: Fri Mar 03, 2006 8:53 am
by duk
didn't resolve...

this session_write_close says:

Code: Select all

End the current session and store session data
i dont want to store any data i need to destroy everything..

i have tried with a Meta tag didn't resolve to... strange because if i execute session_destroy() in form.php it destroy all $_SESSION's... it sounds like if session_destroy not being call in the same dir or the same file don't destroy $_SESSION's from other scripts or dirs

i want to to the logout.php as it is... what can i do... ??

Code: Select all

<?

setcookie("CINTRA", $_COOKIE['CINTRA'], time()-5184000);
session_destroy();
session_write_close(); 
//ob_end_flush();
header("location: /");
?>

Posted: Fri Mar 03, 2006 9:29 am
by AGISB
You got to empty the SESSION array and destroy the cookie

Code: Select all

setcookie("CINTRA", '', 0); 
$_SESSION = array();
session_destroy();

Posted: Fri Mar 03, 2006 10:06 am
by duk
didn't work to.. i do a logout
like http://localhost/logout.php when i return to http://localhost/forms/apf/form.php and i still have my all $_SESSION'S variables, after in logout.php i have destroy the session and empty the array

Code: Select all

<?

setcookie("CINTRA", $_COOKIE['CINTRA'], time()-5184000);
$_SESSION = array();
session_destroy();
session_write_close();
//ob_end_flush();
header("location: /");
?>

Posted: Fri Mar 03, 2006 10:09 am
by Jenk
AGISB wrote:You got to empty the SESSION array
No you don't.


duk - try this:

Code: Select all

<?php
//logout.php

setcookie('CINTRA', '', time()-3600);
session_write_close();
header('Location: http://www.yourdomain.com/index.php');

?>

Posted: Fri Mar 03, 2006 10:16 am
by patrikG

Posted: Fri Mar 03, 2006 10:25 am
by duk
i cant understand... and im sure that the script form.php is not getting any information from database because for example, i have input another name: duk, then i do my logou i return to the page and it show me duk as name... and should appear blank.

this form.php is 3000 and some lines its why i didn't put here yet but if someone wants to see i put...

Code: Select all

<?

setcookie("CINTRA", '', time()-3600);
session_write_close();
header("location: http://localhost/index.php");
?>
im thinking in something in the same page as form.php <body onUnload="javascript:logout();">

where logout to the session_destroy() in the same page...

Posted: Fri Mar 03, 2006 10:45 am
by duk
omg, i found why was doing that.

was missing session_start() :oops: noob... but no one saw it to lol, and because the redirection was being maded i never saw the error.

Code: Select all

session_start();
setcookie("CINTRA", '', time()-3600);
session_destroy();
//session_write_close();
header("location: http://localhost/index.php");

Posted: Fri Mar 03, 2006 11:00 am
by Maugrim_The_Reaper
lol. At least you saved us more headless chicken antics...;)