Page 1 of 1

$_SESSION[] variables not working in Opera

Posted: Sat Apr 11, 2009 1:42 pm
by social_experiment
I have a problem with $_SESSION[] variables not being available to Opera. I have a login script that re-directs the user to a member page once the correct username and password has been entered. The example is very simple and it's merely to demonstrate the point. I've tried this with FF / IE7 and Opera ( ver 9.62 ). In FF and IE 7 it works fine, you get directed to the member page if you are correct and back to the login page if you are not.

In Opera however it redirects you to the login page regardless of whether the information posted is correct.

This is the code for page that checks if the username and password is correct :

<?php
session_start();

if ( ($_POST['userN'] == 'admin') && ($_POST['passW'] == 'mypass') ) {
session_regenerate_id();
$_SESSION['NAME'] = $_POST['userN'];
session_write_close();
header("location: member.php");
exit();
}
else {
header("location: login_form.php");
exit();
}

?>

This is the code for the 'authorise' page :

<?php
session_start();

if ( !isset($_SESSION['NAME']) ) {
header("location: login_form.php");
exit();
}

?>

Finally the code for the member page ( don't know if it is relevant but just in case ) :

<?php
@require('authorise.php');
?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo $_SESSION['NAME']; ?></title>
</head>

<body>
<?php echo "Welcome ". $_SESSION['NAME'].""; ?>
</body>
</html>

I thought that maybe it was the include because i posted this elsewhere and got some information that it might have something to do with the include() and the header information not being sent so i changed the include to include_once(), require() and require_once() but it had the same effect.

Below are what I am assuming is header information. Im using XAMPP and the data below came from the apache/logs/access.log. I purposely logged in with the wrong details to see if it made a difference to the header information.


FireFox

127.0.0.1 - - [05/Apr/2009:13:08:36 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:34:09 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:34:09 +0200] "GET /dotQ/member.php HTTP/1.1" 200 319

FireFox – Incorrect Login Details

127.0.0.1 - - [05/Apr/2009:13:41:18 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:50:12 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:50:12 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512


Internet Explorer 7

127.0.0.1 - - [05/Apr/2009:13:35:14 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:35:22 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:35:22 +0200] "GET /dotQ/member.php HTTP/1.1" 200 319

Internet Explorer 7 – Incorrect Login Details

127.0.0.1 - - [05/Apr/2009:13:38:59 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:39:04 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:39:05 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512

Opera 9.62

127.0.0.1 - - [05/Apr/2009:13:36:24 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:36:24 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:36:24 +0200] "GET /dotQ/member.php HTTP/1.1" 302 –

Opera 9.62 – Incorrect Login Details

127.0.0.1 - - [05/Apr/2009:13:51:34 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512
127.0.0.1 - - [05/Apr/2009:13:51:34 +0200] "GET /favicon.ico HTTP/1.1" 200 30894
127.0.0.1 - - [05/Apr/2009:13:51:38 +0200] "POST /dotQ/login_exec.php HTTP/1.1" 302 -
127.0.0.1 - - [05/Apr/2009:13:51:38 +0200] "GET /dotQ/login_form.php HTTP/1.1" 200 512

PS. I have also tried by checking a username && password against a record in a MySQL database and it did the same thing :|

Re: $_SESSION[] variables not working in Opera

Posted: Sat Apr 11, 2009 10:49 pm
by yacahuma
i never use session_write_close(). php.net says it is use for frames. Are you using frames on your site?

Re: $_SESSION[] variables not working in Opera

Posted: Sun Apr 12, 2009 6:00 am
by social_experiment
No, it's just a simple php page, no frames involved.

Re: $_SESSION[] variables not working in Opera

Posted: Sun Apr 12, 2009 8:36 am
by yacahuma
remove that part of the code. also run your code with E_ALL in php.ini to make sure you get all errors and warnings. One of the best things about PHP, is that almost all the time, it tells you exactly what is wrong

Re: $_SESSION[] variables not working in Opera

Posted: Tue Apr 14, 2009 1:15 am
by social_experiment
I removed the line of code but got the same response, i then decided to test the script on a machine running XP instead of my Vista and it works fine. I also re-installed XAMPP on my current machine and it still doesn't log me in through Opera. Im thinking its a problem between Vista and XAMMP. Thanks for all the help on this one :)

Re: $_SESSION[] variables not working in Opera

Posted: Tue Apr 14, 2009 8:37 am
by yacahuma
when I bought my laptop in came with Vista. I had problems with php and a bunch of other things. So I upgraded to XP.