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 #175700 is a reply to message #175696] Fri, 21 October 2011 21:43 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.
>

Weird, my phpinfo() says: "Session Support enabled"
but even with code like this
<?php
session_start();
echo ++$_SESSION['test'];
?>
just prints "session_start(); 1" - and i'm wondering why it's printing
session_start(); in the browser, seems like it doesn't know this
command...? Weird, any clues...?

Thanks alot!
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:42:52 GMT 2024

Total time taken to generate the page: 0.04646 seconds