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 #175704 is a reply to message #175700] Fri, 21 October 2011 23:06 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 10/21/2011 5:43 PM, h wrote:
> 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

That's because the code you posted is not what you have in your script.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Sat Oct 05 13:23:00 GMT 2024

Total time taken to generate the page: 0.04511 seconds