atticus Posted December 11, 2007 Share Posted December 11, 2007 I am getting the following errors for a session/login script. errors: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at ..../html/cms/cms/admin/index.php:1) in ..../html/cms/cms/admin/index.php on line 2 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at ...html/cms/cms/admin/index.php:1) in ..../html/cms/cms/admin/index.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at ..../html/cms/cms/admin/index.php:1) in .../html/cms/cms/admin/index.php on line 8 <?php session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location: login.php'); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/ Share on other sites More sharing options...
BenInBlack Posted December 11, 2007 Share Posted December 11, 2007 do this <?php ob_start(); session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page ob_clean(); header('Location: login.php'); exit; } ?> and research Output Buffers Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412210 Share on other sites More sharing options...
runnerjp Posted December 11, 2007 Share Posted December 11, 2007 ob_clean(); but your not ob_clean(); add this to the top of code! Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412214 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2007 Share Posted December 11, 2007 The error message referring to output started .... at line 1, is due to white-space before the <?php tag or the BOM characters at the start of a file that is saved as UTF-8 format instead of an ANSI/ASCII format file. Output buffing in the script won't fix this particular problem. Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412221 Share on other sites More sharing options...
sureshp Posted December 11, 2007 Share Posted December 11, 2007 I think that you have to check with the admin/index.php file code to make sure whether the first line is a blank one or not. If it is a blank line or any HTML code present there, just remove it. Suresh P Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412223 Share on other sites More sharing options...
atticus Posted December 11, 2007 Author Share Posted December 11, 2007 thanks everyone...there was no whitespace at the top...however I did change some of the format, but now I am getting a completely blank screen or this error: Warning: Cannot modify header information - headers already sent by (output started at /html/cms/cms/admin/index.php:1) in //html/cms/cms/admin/index.php on line 11 <?php ob_clean(); ob_start(); session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page ob_clean(); header('Location: login.php'); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> I did change the charset=utf-8 to ANSI/ASCII in the html, but it did not seem to make a difference. For some reason it is not redirecting to login.php Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412230 Share on other sites More sharing options...
atticus Posted December 11, 2007 Author Share Posted December 11, 2007 thanks...I changed the file format in my editor to ANSI and the problem was solved. I really appreciate the help and I will be researching ob_clean(); thanks for the tip. Link to comment https://forums.phpfreaks.com/topic/81237-solved-sessions-header-problem/#findComment-412240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.