Re: Sessions

From: Date: Mon, 10 Jul 2000 18:36:38 +0000
Subject: Re: Sessions
Groups: php.general 
Request: Send a blank email to php-general+get-5775@lists.php.net to get a copy of this message
Brian/Ray, That's not how sessions work. A registered variable's value is saved at the end of the script, not when it is registered. Look at these 2 scripts: session1.php <?php session_start(); $x="Empty"; session_register("x"); $x="Full"; header("Location: session2.php"); ?> session2.php <?php session_start(); echo("x = $x"); ?> The result of calling session1.php in my browser is x = Full This would not be true if a variable's value was saved when it was registered instead of at the end of the script. Regards, Carroll Barrett Regards, Carroll Barrett -----Original Message----- From: Brian T. Allen <brian@purenetfx.com> To: Ray Parish <rparish@digitalwebzone.com>; php-general@lists.php.net <php-general@lists.php.net> Date: Monday, July 10, 2000 1:21 PM Subject: Re: [PHP] Sessions >At first glance it looks like you are incrementing $count AFTER you are >putting it into the session. So you visit the page, count = 0, you store 0 >in the session, increment to 1, then display 1. > >If you increment first, you would visit the page, count = 0, increments to >1, stores 1 in the session, and displays 1. The next time it would >increment to 2, etc... > > >> <? >> >> // File name: count_me.php >> >> // if a session does not yet exist for this user, start one >> >> session_start(); >> session_register('count'); >> >> $count++; >> >> echo "<p>You've been here $count times. Thanks!</p>"; >> ?> >> >> I have this sample script that DOES NOT increament up each time I click >> refresh? It stays at 1? >> Thanks >> Ray >> >> >> >> --

« previous php.general (#5775) next »