FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » simple session question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: simple session question [message #175705 is a reply to message #175696] Fri, 21 October 2011 21:17 Go to previous messageGo to previous message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma:
Member
On Oct 21, 11:19 am, Thomas Mlynarczyk <tho...@mlynarczyk-
webdesign.de> wrote:
> cerr schrieb:
>
>> if(!isset($_SESSION['stp'])) {
>>   session_start();
>>   $_SESSION['stp'] = 0;
>>   echo "session started<br>\n";
>> }
>
> You need to call session_start() on *every* page request, not just when
> you initialize the session (think of it as
> "session_start_or_continue()"). The $_SESSION superglobal does not exist
> until you have called session_start(), so your code above won't work.
>
>> switch($_SESSION['stp']) {
>>   case 0: $_SESSION['stp'] = $_SESSION['stp']++;
>>              echo "stp:".$_SESSION['stp'];
>>              break;
>>   case 1: $_SESSION['stp'] = $_SESSION['stp']++;
>>              echo "stp:".$_SESSION['stp'];
>>              break;
>>   case 2: $_SESSION['stp'] = $_SESSION['stp']++;
>>              echo "stp:".$_SESSION['stp'];
>>           $_SESSION['stp'] = 0;
>>              break;
>
> You're missing a } here. But even with that and the session_start()
> issue fixed, it always prints 0. I'm not quite sure why, but anyway your
> code is unnecessarily complicated. Here's my version:
>
> session_start();
> if ( !isset( $_SESSION['stp'] ) )
> {
>      $_SESSION['stp'] = 0;
>      echo "session started<br>\n";
>
> }
>
> echo $_SESSION['stp'];
> $_SESSION['stp'] = ( $_SESSION['stp'] + 1 ) % 3;
>
> I use the modulo operator % to achieve the cycling through the values 0,
> 1, 2.


Hi Thomas,

Thanks for the reply! Using your code, the variable always stays 0
too, it doesn't change ever. I always see "
session_start(); session started
0" printed, seems like it may not know sessions, is that possible at
all?

Thanks!
Ron
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session cookie: client side
Next Topic: by get this format my explode file name like this through php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 22 06:44:01 GMT 2024

Total time taken to generate the page: 0.04561 seconds