Jump to content

session error, when there shouldn't be one? short file


XpertWorlock

Recommended Posts

Hi, I'm getting this error,

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /******************************) in ********************************** on line 4

 

with this file

 

<?php

SESSION_START();
include '../siteLayout.php';

dbConnect();
$result = mysql_query("SELECT * FROM users
WHERE userName ='test'");

$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";
?>

 

Are you saving this file in UTF-8?  If you are, make sure to turn off the BOM (Byte Order Mark) that some editors put in there at the beginning of the file.  These get send out as output before you can send headers, so your script fails.

try using notepad2 (http://www.flos-freeware.ch/notepad2.html) you can specify what format to save files in.

 

also make sure there is no output being sent to the browser becore the session_start(); function is called.  even a single space or linebreak will give you an error.

<?php ob_start();
session_start();

include '../siteLayout.php';

dbConnect();
$result = mysql_query("SELECT * FROM users
WHERE userName ='test'");

$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

ob_flush_end();
?>

If you would post the most important part of the error message, where the output is started at that is preventing the headers from being sent, someone could directly help you with what is causing the problem. You either have white space (space, tab, newline) or BOM characters before the <?php tag. Repost your error message, xxxxxx out your path information, but leave the file names and the :x number telling where the output is occurring.

 

And since the session_start() is the first php statement in the file, the error means that something is being output before the <?php tag and an ob_start() statement in the code will have no effect. As always, it is better to find and fix problems than to try and fix symptoms.

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.