Jump to content

Header and Session


doubledee

Recommended Posts

What do you mean?

 

I was wrapping up functionality that updates "last_activity" in MySQL whenever a User does something on my website so that I can keep their "Online Status" near real-time.

 

I broke something, and now I am getting the famous "Data already send to Headers"!!  >:(

 

Trying to trouble shoot.

 

Maybe I should start a more aptly labeled thread about this problem?

 

 

Debbie

 

Link to comment
Share on other sites

All you have to do is ensure you do not output any data before you begin the session.

 

Setting variables is fine but if you say "echo" or anything and the try to start the session it will fail.

Link to comment
Share on other sites

This is the error you will receive when attempting to send output to the browser before starting the session

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\test.php:3) in C:\xampp\htdocs\test\test.php on line 5

 

So, the error seems pretty obvious to me. FYI: that took me all of 2 minutes to test.

//Comment/uncomment to test the difference
//echo "Start the session";

session_start();

echo "Session started";

Link to comment
Share on other sites

To sum it up, no it does not.

 

It modifies the headers being sent, but it doesn't actually output anything.

 

That is what I thought.

 

Grrrr....  I fear this is going to be one of those "Bugs from Hell" to chase down?!

 

I am testing and getting sporadic results.  :(

 

Will post more soon...

 

 

Debbie

 

Link to comment
Share on other sites

The 'headers already sent' error tells you where the output is started:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\test.php:3) in C:\xampp\htdocs\test\test.php on line 5

Link to comment
Share on other sites

 

 

Don't minimalize my problem.  If it was that easy I wouldn't be asking for help...  >:(

 

I'll start a new thread describing this problem which is between several scripts.

 

Who is minimizing your problem? I simply showed the error that would be displayed if you attempted to output to the browser before starting the session. If that was the error you had received you should have known that the problem was with the problem was with the position at which the session was started. However, I also pointed out that it would have taken less time to verify that for yourself rather than posting a topic on the forum.

 

To paraphrase what you have told others - If you don't like my responses, don't post stupid questions for me to respond to.

Link to comment
Share on other sites

To paraphrase what you have told others - If you don't like my responses, don't post stupid questions for me to respond to.

 

Were you not held enough as a child?

 

My must you frequently be so hostile?

 

I'm not hostile, I'm just making a statement regarding a person's inability to even attempt simple problem solving techniques. You are the one who just made an unfounded derogatory statement. But, what I believe is that my parents helped me to become an independent person who is able to utilize critical thinking skills to determine when a problem is something I can solve on my own. Plus, my parents taught me not to steal, which is what I would be doing if I utilized someone's copyrighted photo as my avatar.

Link to comment
Share on other sites

This is an unnecessary argument chaps.

 

The problem has been clearly explained by Psycho with a perfect example. Your actual problem may seem far more complex but ultimately will boil down to you starting a session after outputting something to the browser.

 

As pointed out by xyph, the code should indicate where the error is coming from.

 

To thoroughly debug your script try killing it at different steps of the execution using:

 

echo "Hello World"; die;

 

Then you'll be able to determine at what stage things are going wrong. Just a suggestion.

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.