FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Problem using sessions_start()





biljap
Hi!

I have a big problem with sessions and I don’t know why it’s happening…

I have to use sessions on two pages and when I load one of them everything works fine, but if after that I try to load the other page I get this:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at…

at the line where I use session_start().

Does anybody know how to solve this?

Thanks!
LukeakaDanish
What PHP is saying is that the "headers" have already been sent. The session info is sent in the headers, so if you haven't started the session before the headers are sent, you can't!

The headers include all sorts of info about the page, and they are sent as soon as any text is sent to the user!

Following are a couple of code examples of where headers are sent:
Code:


1:

[HEADERS ARE SENT HERE]<html>

<head>

</head>

<?php echo 'hi'; ?>

</html>



2:

<?php

echo 'hi'; [HEADERS ARE SENT HERE]

?>
<html>
...




Hope you understood that.
ThomasDesigns
What he means is, make sure session_start() is the first line of php before any other text in your page. If the php file with session_start() is included into another file, make sure it is included BEFORE the <html> tag. Else, move session_start() to the file that the previously stated file is included to.
Mememe
Yup, and make sure it is the first thing. Even with spaces before it can cause problems.
SlovenianBoy
Put in first line:

Code:

<?php ob_start(); ?> 
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.