At 07:28 PM 3/30/2011, Ashley Sheridan wrote:
On Wed, 2011-03-30 at 19:20 -0400, Ethan Rosenberg wrote:
> Dear List -
>
> Thank you for your help in the past. This an update on my
session problems.
>
> Here is a simple test program. It never increments the session
> counter; ie, does not detect that $_SESSION has been set.
>
> <?php session_start(); ?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <html>
> <body>
>
> <?php
>
>
> if(isset($_SESSION['views']))
> $_SESSION['views']=$_SESSION['views']+1;
> else
> $_SESSION['views']=1;
> echo "Views=". $_SESSION['views'];
> ?>
> </body>
> </html>
>
> I have no idea what is wrong.
>
> I need to make my session variables work so that I can finish a project.
>
> Help and advice, please.
>
> Ethan Rosenberg
>
> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>
>
>
That code works perfectly for me, only thing I would change is the
$_SESSION['views']=$_SESSION['views']+1;
line to
$_SESSION['views']++;
for readability. If you're using Firefox, grab the Firebug plugin, which
should show you the headers that are being sent to and from the server
to the browser. From that, you might get an idea why the sessions don't
seem to be working. Just to make sure, turn on display_errors in your
php.ini file and restart Apache. Some whitespace (space or new line, for
example) before that first <?php line could cause the headers to send
and the sessions headers to fail (headers already sent error) which
would give you the problems you're seeing now. Also, some editors have
issues with the BOM (byte order marker) which could cause white-space to
be perceived where there is none. If you are sure there isn't any, then
try saving the script with a different character encoding to test if it
is the BOM causing problems.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
++++++++++
Ash -
Thanks.
What did it was to 1] explicitly declare the character set and 2]
close and restart Apache.
Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php