|
Session not working on live server
Hi,
It's about login script in PHP and MySQL.
While everything is cool on localhost (xamp), when the files are uploaded to live server (PHP 4.3.2) Session seems not to work. To make it even more confusing I've tested the script on two other web servers (PHP 4.4.9) and it worked fine.
A few snippets:
LOGIN.PHP
//Start session
session_start();
.............................
.............................
.............................
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
session_write_close();
header("location: members.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
----------------------------------------------------
MEMBERS.PHP
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: access-denied.php");
exit();
}
?>
........more code..............
......................................
and of course access-denied.php loads in as $_SESSION['SESS_MEMBER_ID'] doesn't exist
I've also run little test on the server and it worked FINE:
SESSION.PHP
<?php
session_start();
$_SESSION['text'] = 'some text some text';
?>
<a href="session_after.php">test</a>
SESSION_AFTER.PHP
<?php
session_start();
echo $_SESSION['text'];
?>
RESULT --> printed "some text some text". All good
Last test I did was modification of the above and it didn't work:
<?php
session_start();
$_SESSION['text'] = 'some text some textn';
header("location: next_page.php");
?>
next_page.php
<?php
session_start();
echo $_SESSION['test'];
?>
RESULT ---> NOTHING!
I lost my head and don't know anymore what's going on. Thanks for any help
Jacek
|