Jump to content

Diagnosing headers already sent errors


E_Leeder

Recommended Posts

I'm trying to diagnose headers already sent errors. I know that I can see the line and comment it out (or do something) based on the error given, but what I don't understand is why they seem to occur sometimes but not others.

 

The code below sends things to the browser before calling session_regenerate_id(true), which will cause headers already sent errors if headers have already been sent.

<?php

echo 'hello world';
$test_variable = 'some variable to var_dump';
var_dump($test_variable);
session_regenerate_id();

?>

I thought that this should fail and give me a headers already sent error, but it doesn't. I frequently echo to a page before calling a header action, and sometimes it works, sometimes it doesn't, like in the case above. What's going on to give me an error elsewhere but not here?

Link to comment
Share on other sites

Is your experience in testing/developing, in different environments, e.g working locally with wamp or xampp or something vs. a hosted server, or multiple hosted servers? Because the most common cause is that it depends on what the error reporting levels are set at, either in the php.ini file or in some script itself.

Link to comment
Share on other sites

I am in a dev environment with all errors on (I think... the setting is: error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT)). Does the code I posted cause an error for you? (Other things cause me headers already sent errors.)

Edited by E_Leeder
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.