Forum Moderators: coopster

Message Too Old, No Replies

Session Error

         

LinusIT

7:05 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



Hi

I'm getting the following error message when logging in on a site I'm developing.

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /mnt/array1/system/web/htdocs/login.php on line 55

Warning: Cannot modify header information - headers already sent by (output started at /mnt/array1/system/web/htdocs/includes/config.php:8) in /mnt/array1/system/web/htdocs/login.php on line 60



Here is the code with lines 55 & 60 highlighted


//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id(); //Line 55
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_USER_ID'] = $member['id'];
$_SESSION['SESS_USERNAME'] = $member['username'];
session_write_close();
header("location: admin.php"); //Line 60
exit();
}else {
//Login failed
header("location: login.php?login=failed");
exit();
}
}else {
die("Query failed");
}
}

I have this code on my domain and it works fine, however I'm trying to get it working on a Link Station NAS box. Could it be that sessions are disabled or something?

Any help would be greatly received.

JAB Creations

11:07 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've encountered odd server configurations with a couple hosts who didn't have PHP sessions enabled by default...no idea why because it's an absurd scenario. Try using isset($_SESSION) and print_r($_SESSION) to see what you have.

If it's a NAS that you have access to see if you can determined the path to the session files the server should be writing, if you don't see them then sessions are probably not enabled for some reason.

- John

henry0

8:56 pm on Feb 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like a headers problem which will block anything else.
Check if output buffering in your php.ini is on
if not turn it on or ask your server admin to give it a value.

LinusIT

10:10 pm on Feb 21, 2011 (gmt 0)

10+ Year Member



I've solved it now, the problem was empty lines in the config.php and database.php files. Really strange how they would cause this issue.

coopster

4:59 pm on Feb 22, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Output is output, including blanks. See the header() [php.net] PHP manual page for more information:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.


As henry0 mentioned you can always use output buffering too.