You are here: Re: Sessions not Working on WAMP « PHP Programming Language « IT news, forums, messages
Re: Sessions not Working on WAMP

Posted by vdP on 10/15/42 11:35

PulsarSL@gmail.com wrote:
> Hey
>
> I have a WAMP setup (windows/apache/mysql/php). I'm running the latest
> version of all of them with a default installation of all of them. PHP
> works great with apache (as a module, not cgi), except that sessions
> aren't working. The script at the bottom of this post never increments
> my hit count. Do I need to turn sessions on somehow in php.ini?
>
> Thanks,
>
> PulsarSL

> ----
>
> Works great on a remote web server I have, so it's not the script...
>
> <?php
> // Initialize a session. This call either creates
> // a new session or re-establishes an existing one.
> session_start( );
>
> // If this is a new session, then the variable
> // $count will not be registered
> if (!session_is_registered("count"))
> {
> session_register("count");
> session_register("start");
>
> $count = 0;
> $start = time( );
> }

If you use the latest version of WAMP or PHP, you are using PHP 5. This
means that register_globals is disabled by default. Therefore you should
use the superglobal $_SESSION, instead of session_is_registered and
session_register. Quoting the manual-page of session_register at php.net
( http://nl3.php.net/manual/en/function.session-register.php)
"If you want your script to work regardless of register_globals, you
need to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_register(), it
will not work in environments where the PHP directive register_globals
is disabled."

Using $_SESSION the code can be rewritten as (may contain typos)
if (!isset($_SESSION['count'])){
$_SESSION['count']=0;
$_SESSION['start']=time();
} else {
$_SESSION['count']++;
}

Hope this helps.

vdP

 

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

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