session_destroy as logout

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

session_destroy as logout

Post 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 ??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think your issue is code specific.. show some.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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: /");
?>
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

You got to empty the SESSION array and destroy the cookie

Code: Select all

setcookie("CINTRA", '', 0); 
$_SESSION = array();
session_destroy();
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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: /");
?>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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');

?>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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...
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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");
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

lol. At least you saved us more headless chicken antics...;)
Post Reply