Jump to content

[SOLVED] Sessions, Header Problem


atticus

Recommended Posts

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

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.