Posted by Alexey Kulentsov on 07/19/07 00:36
Good Man wrote:
> "dpinion@gmail.com" <dpinion@gmail.com> wrote in
> news:1184785906.714977.76830@x35g2000prf.googlegroups.com:
>
>> Greetings,
>> I am trying to do some simple session stuff. However it does not seem
>> as though the session variable is being created for my site. I am
>> running the latest version of PHP and apache that I installed as part
>> of WAMP. Machine is XP SP2.
>>
>> Basically I am trying to do something simple such as:
>>
>> <?php
>>
>> // initialize a session
>> session_start();
>>
>> // increment a session counter
>> $_SESSION['counter']++;
First of all, never use uninitialized variables. Even if you think
this is o.k. if(!isset($_SESSION['counter'])) $_SESSION['counter']=0; is
not hard code but now you don't depend of session vars behavior modified
with every PHP version.
>> // print value
>> echo "You have viewed this page " . $_SESSION['counter'] . " times";
>
> you don't see your new session/cookie value until you call it from the
> NEXT/FOLLOWING page.
>
> Also, this might make more sense:
> $_SESSION['counter'] = $_SESSION['counter']++;
Will never increment it because of post-increment.
I think you mean this:
$_SESSION['counter'] = $_SESSION['counter']+1;
Navigation:
[Reply to this message]
|