简体   繁体   中英

Having an error with my PHP code (Cannot send cookie cache, session cache limiter)

I am trying to create a register and login page. When attempting to upload the code to our servers, it creates two errors:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php:52) in /Applications/XAMPP/xamppfiles/htdocs/tisun_search/functions.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php:52) in /Applications/XAMPP/xamppfiles/htdocs/tisun_search/functions.php on line 2

I've tried inspecting the problem in the functions.php file, there are no whitespaces nor any visible errors.

I was wondering if anyone would happen to know any other reason why this error may be occuring and what may be the solution to fix this error.

Below is the beginning of my functions.php code (Without the php tags).

session_start(); 

function loggedin() 
{
if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id']))
{
return true;
    }
    else
    {
    return false;
    }
}

The code below shows where the error is occurring

The only way to fix that, is walking through all includes and check whether they are either doing some output (echo, printf) or, most common, in a pure include (classes etc) you have spaces and NL after the final closing ?>:

....
} // end of class xyz

/*
 * some comments
 */
············¶
?>·················¶
¶
¶
¶
¶
<--- EOF

NLs might not be an issue but trailing spaces and NLs. Once you're using Eclipse, you can configure it to automatically remove these artifacts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM