Reply to Re: $_SESSION variable not carrying

Your name:

Reply:


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;

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация