Sessions not Working on WAMP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?




Works great on a remote web server I have, so it's not the script...


  // 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"))

    $count = 0;
    $start = time(  );

  $sessionId = session_id(  );

   "-//W3C//DTD HTML 4.0 Transitional//EN"
   " " >
    <p>This page points at a session
    <br>count = <?=$count?>.
    <br>start = <?=$start?>.
    <p>This session has lasted
        $duration = time(  ) - $start;
    echo "$duration";  


Re: Sessions not Working on WAMP wrote:
Quoted text here. Click to load it

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  
( )
"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'])){
} else {

Hope this helps.


Re: Sessions not Working on WAMP

Quoted text here. Click to load it

Yes, thank you.


Site Timeline