Page 1 of 1

sessions do not work

PostPosted: 05. February 2008 13:49
by TheTitans
None of my PHP sessions are working. For some reason they aren't being stored properly because my php login script that uses sessions isn't working. However, I know that the script is coded properly because it works on my other server, but not xampp.

In my php.ini file, it says that sessions are stored in the C:\xampp\tmp folder. I do see a few session files there. I'm not sure if they are from my script or not though. Need some help.

PostPosted: 05. February 2008 15:14
by Scory
Sessions requires cookies - are cookies enabled in your browser for the domain you are testing?

PostPosted: 06. February 2008 00:39
by TheTitans
I am testing under http://localhost/
My actual browser, Firefox, does allow cookies.
Do I need to edit a setting in my php.ini file?

PostPosted: 06. February 2008 11:37
by sari42
>I do see a few session files there
then apparently sessions can be created by php.

>I know that the script is coded properly because it works on my other server,
that's no proof.

compare the outputs of
<?php phpinfo(); //saved as info.php ?>
on both servers, maybe the "other" server has register_globals "On" or allow_short_open_tags "On" or somesuch.

_________
p.s.
simple test script:
Code: Select all
<?php
//store as, e.g., session_wr.php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
@session_start();
echo 'php-session write/read test, please reload the page (F5) ...<p>
$_SESSION["ts"] was ',
empty($_SESSION['ts'])
? '<b>not yet</b> set.'
: 'updated <b>' . (time() - $_SESSION['ts']) . '</b> seconds ago';
$_SESSION['ts'] = time();
?>

PostPosted: 06. February 2008 12:31
by TheTitans
register_globals is "on" on the other server as well as short_open_tag. In xampp, register_globals is turned off, but short_open_tag is turned on.

PostPosted: 06. February 2008 12:49
by sari42
quick and dirty workaround:
set register_globals "On" in php.ini or
php_value register_globals 1 in .htaccess

or better amend all your scripts (more secure and mandatory for php6, see http://php.net/manual/en/security.globals.php ),
e.g., change $login_name to $_POST['login_name']