You are here: Re: $_SESSION variable not carrying « PHP Programming Language « IT news, forums, messages
Re: $_SESSION variable not carrying

Posted by Jerry Stuckle on 07/19/07 04:39

Alexey Kulentsov wrote:
> 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;

Or, just

$_SESSION['counter']++;

$_SESSION['counter'] = $_SESSION['counter']++;

is an "undefined operation" - it could contain the old value or the new
value. Either result could be considered "legal".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this 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

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