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
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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.