Jump to content

Warning apears i don´t know why


torsuntsu

Recommended Posts

Hello, i´m getting a warning:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/sistemag/public_html/index.php:3) in /home/sistemag/public_html/core/init.php on line 1

 

and i can´t figure it out why.

I just moved my code to another server and this warning began to apear.

On the previous server i got no warnings.

Can somebody help me with this one?

 

Many thanks,

TorSunTsu

Link to comment
https://forums.phpfreaks.com/topic/283387-warning-apears-i-don%C2%B4t-know-why/
Share on other sites

line 3 (and probably lines 1 and 2) of index.php are sending output to the browser that is preventing the session_start() from working.

 

the reason you were not having this problem on a different server is because output_buffering was turned on in your php.ini, thereby allowing your code to function even though it is not properly organized.

 

you need to have the session_start() statement before you send any characters of any kind to the browser (even the html doctype tag is made up of characters and must come after the session_start() statement.)

How can i solve this problem?

The session_start() function is called in the init.php file like this:

<?php 
session_start();
error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
if (logged_in()===true)
{
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id,'user_id','username','password','first_name','last_name','email');
if (user_active($user_data['username'])===false){
session_destroy();
header('Location: index.com');
exit();
}
}
$errors = array();
?>
 
It´s the first thing being called, and in the other pages i include this file in the very beginning...
Help...:-( 

the reason you were not having this problem on a different server is because output_buffering was turned on in your php.ini, thereby allowing your code to function even though it is not properly organized.

or the error settings for warning level errors are disabled (which is more likely to be the case than output_buffering being turned on).

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.