Session not working as expected

I’m trying to set up a session to maintain a login on a site I’m building. I’m new at PHP, but I’ve done some reading and I think my code is ok and it may be configuration-related. I need some help though, so any advice would be greatly appreciated. I minimized my code quite a bit in order to try to pinpoint the problem. Here are two files that I’ve been using:

logintest.php

[code]<?php

session_start();

$_SESSION[‘USERNAME’] = “blueliner”;
$_SESSION[‘FIRSTNAME’] = “Danny”;

echo "You are logged in as " . $_SESSION[‘FIRSTNAME’] . “
”;

?>

Go[/code]

test.php

[code]<?php

session_start();

echo "You are logged in as " . $_SESSION[‘FIRSTNAME’] . “
”;

?>[/code]

The first page displays exactly as I would expect, but when I click the link to get to the test.php page, the session variable doesn’t come up. The server on which I’m renting space is running PHP 4.4.7.

TIA

Make sure there is nothing outputted (like spaces or whatever) before session_start();

Everything else looks good!

How much code did you remove?

Originally I wrote the pages with a lot more than what I entered here, but when things didn’t work, I cut them down to exactly what I posted above and the FIRSTNAME variable still doesn’t show on the logintest.php page. That’s what makes me think there’s some sort of configuration setting or something that I’m missing.

I solved the problem. I added session.cookie_secure = Off to my php.ini. It didn’t appear in my php.ini, so I assumed that PHP was using the default (Off), but I guess my host had turned it on at another level.

Thanks for the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service