/    Sign up×
Community /Pin to ProfileBookmark

Error: Cannot send session cache limiter – headers already sent

[COLOR=”DarkRed”]Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/vila/public_html/alexandra/login.php:1) in /home/vila/public_html/alexandra/includes/session.php on line 2

Warning: Cannot modify header information – headers already sent by (output started at /home/vila/public_html/alexandra/login.php:1) in /home/vila/public_html/alexandra/includes/functions.php on line 25[/COLOR]

Do you know anything about these errors?

This is my session.php

[CODE]<?php
session_start();
function logged_in() {
return isset($_SESSION[‘user_id’]);
}
function confirm_logged_in() {
if (!logged_in()) {
header(“Location: new_user.php?sign_up=no”);
exit;
}
}
?>
[/CODE]

and this is how I call it in the pages

[CODE]<?php require_once(“includes/session.php”); ?>
<?php confirm_logged_in(); ?>[/CODE]

in the first two lines with no space or anything else preceding them.

Format is UTF-8.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscJun 15.2010 — Ah, the old headers already sent problem. There's only about 1000 (I exaggerate) of these questions posted on here, per week.

So, the thing is, when dealing with headers and PHP, things that require no headers to be issued before them are :

1) A cookie (i.e. setcookie()) or

2) session_start() or

3) header('Location: ......');

The thing is, if content (any content, even whitespace) is sent to the browser before these headers, then it will get served as, for example, text/html. Now, a cookie is not text/html, nor is a session, nor is a redirect. Each of these examples in the list above requires a different header to be sent first, which allows that data to be interpreted correctly, and afterwards it will send a different header (e.g. text/html) when the content is sent.

So what does all that mean?

Well, according to your first error above, there is something (most likely content) on line 1 of login.php that is being sent to the browser first and causing a header to be sent. This could by whitespace, a character, content, or even an invisible BOM.

By the way, when I say whitespace, I mean whitespace BEFORE you open your PHP tag ( <?php ). Whitespace after you open your <?php tag doesn't count.

Your second error is actually just another alert reiterating your first error, when you try and send PHP headers on line 25 of functions.php. It's not a new error, it's the same one, so if you fix the first one, you'll be fine.

So go to login.php, and see if there's anything on line 1 before your opening php tag, if there is, remove it and try again.
Copy linkTweet thisAlerts:
@fouskalexauthorJun 15.2010 — There is nothing at all before the php tag. I've checked it many times.

I've read that it's sth with encoding in UTF8 that sends some characters before anything else is sent. That BOM thing you sent me. How do I prevent this? And how can I see if this is the problem?
Copy linkTweet thisAlerts:
@aj_nscJun 15.2010 — Open it up in Notepad++, go to encoding, and select UTF-8 without BOM. Then save it.

If you haven't discovered Notepad++ for developing yet, then download it and thank me later ?
Copy linkTweet thisAlerts:
@fouskalexauthorJun 15.2010 — You cannot imagine how many hours I lost looking for a solution.

I could not imagine that it was SO EASY.

Notepad++ is my tool but this was above my knowledge.

You really made my night THANK YOU!!!
×

Success!

Help @fouskalex spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...