Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 24th, 2005, 02:55 AM
PulsarSL@gmail.com
Guest
 
Posts: n/a
Default Sessions not Working on WAMP

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( );
}
else
{
$count++;
}

$sessionId = session_id( );

?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head><title>Sessions</title></head>
<body>
<p>This page points at a session
(<?=$sessionId?>)
<br>count = <?=$count?>.
<br>start = <?=$start?>.
<p>This session has lasted
<?php
$duration = time( ) - $start;
echo "$duration";
?>
seconds.
</body>
</html>

----

  #2  
Old December 24th, 2005, 09:25 AM
vdP
Guest
 
Posts: n/a
Default Re: Sessions not Working on WAMP

PulsarSL@gmail.com wrote:[color=blue]
> 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[/color]
[color=blue]
> ----
>
> 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( );
> }[/color]

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/functio...n-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
  #3  
Old December 24th, 2005, 10:35 PM
PulsarSL@gmail.com
Guest
 
Posts: n/a
Default Re: Sessions not Working on WAMP

[color=blue]
>
> Hope this helps.
>[/color]

Yes, thank you.

PulsarSL

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles