Jump to content

session_start() Error


JustinK101

Recommended Posts

I am trying to put session_start() in a global include file, so basically all my pages call a file called _requires.php simply via:

 

require_once("_requires.php");

 

The very first line in _requires.php is:

 

session_start();

 

It is very odd though, I getting the following error:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at _requires.php:1) in_requires.php on line 2

 

Any ideas why? I am not outputting anything simply calling the require_once function and that require page calls session_start().

 

Link to comment
Share on other sites

login.php which is the first file is like:

 


<?php
    require_once("_requires.php");
?>
<!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">
<head>
.....

 

_requires.php is like:

 

<?php
	session_start();

require_once("classes/Timer.php");
require_once("classes/DatabaseConfiguration.php");
require_once("classes/Error.php");

         ...
?>

Link to comment
Share on other sites

Delete that first blank line above the opening php tag in requires.php. That blank line sends a space to the browser, which is considered to be output to the browser. You can't call session_start after output has been sent to the browser.

Link to comment
Share on other sites

Delete that first blank line above the opening php tag in requires.php. That blank line sends a space to the browser, which is considered to be output to the browser. You can't call session_start after output has been sent to the browser.

 

Same error:

 

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

Link to comment
Share on other sites

Then you didn't do it right. It told you right in the error that the output was started in line 1 of requires.php. Line 1 was the blank line. If you deleted it, then line 1 would be the php opening tag, which would mean that no output would be being sent. Check and make sure you both saved the file, and properly uploaded it to the server (if necessary).

 

Yes, @session_start is a bad idea. The @ sign just suppresses errors, it doesn't fix them. So the error is still there, and your sessions wont work. You should pretty much never use the @ sign.

Link to comment
Share on other sites

This is how my _requires.php file is exactly:

 

<?php session_start();

	require_once("classes/Timer.php");
        require_once("classes/DatabaseConfiguration.php");
require_once("classes/Error.php");

        ....
?>

 

Nothing crazy there, still getting the error.

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.