Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

close a session

0 views
Skip to first unread message

Jean-Marc

unread,
Mar 7, 2002, 6:50:28 PM3/7/02
to
Hello,
I tried session_destroy (who only clears the variables) and
session_write_close to end a session but it didn't work (whereas it
seems the 2nd one should work).
With session_write_close my variables were still there (the counter's
value from tyhe manual).
How can I do to actually destroy he cookie that was set when I first di
session_start so that it's like I never started a session ??

Thank you for the help,
JM

burk

unread,
Mar 7, 2002, 7:46:00 PM3/7/02
to
In article <3C87FCC4...@wanadoo.fr>, jean-m...@wanadoo.fr
says...

Well, it's non-trivial, but this is what I use and it works well enough.
I got this off a post from usenet a couple of years ago... I wish I
remember from who.

// the next four lines kill the session,
// the cookie, and the horse they rode in on.

session_unset();
session_destroy();
$p = session_get_cookie_params();
setcookie(session_name(), "", 0, $p["path"], $p["domain"]);

Hope this helps.

-burk
--
<?php while ($awake) { code() } ?>

Justin Koivisto

unread,
Mar 8, 2002, 9:27:48 AM3/8/02
to
Jean-Marc wrote:

session_destroy() does do what you want. However, what it seems you are
experiencing is that the stale session file is still residing on the
server. This is because the garbage collection routine (the one that
deletes old session files) has not run.

In php.ini, the session.gc_probability has a default value of 1. This
means that 1% of the time that a session_start() is called (or implied)
the gc routine runs. This will leave files on the server for a quite a
while of you don't have a lot of traffic.

You can change this value to something bigger to get rid of the files
more often. I'm sure there is going to be a performance hit on a
high-traffic site, so you will need to consider that as well. You don't
have to change the setting in php.ini, you can do it in your script with:
ini_set('session.gc_probability','70');
where 70 is the value that you want to use. You'll propabally want to
experiment with the setting to find the optimal trade-off between
performance and functionality according to your application and traffic.

--
<?$a=array(306%200,100+17,130-15,232/2,1.05*100,11*10,10*10+7,8*8,
119%100+100,100-3,100+2,21*5,11.5*10,10*4+8*8,50+51,(.14+1)*100,
709%600,1100/10,23*2,33*3,888/8,109);$b='';while(list(,$c)=@each($a))
$b.=sprintf("%c\n",$c);echo str_replace("<br />\n",'',nl2br($b));?>

0 new messages