Jump to content

Warning: Can not send headers - Headers Already Sent


sepoto
 Share

Recommended Posts

 <?phpsession_start();  $productname = trim($_GET['productname']);$productquantity = trim($_GET['productquantity']); if( (!empty($productname) && !empty($productquantity)) && (is_numeric($productquantity)) ) {   $_SESSION['productname'] = $productname;$_SESSION['productquantity'] = $productquantity;$_SESSION['sepysCounter'] = 0;header("Location: http://localhost/Form2.php");}else if(empty($productname) || empty($productquantity)){ echo "A value must be entered for both the Product Name and the Quantity text boxes. Please use the back button to go back to the form"; }else if(!is_numeric($productquantity)){echo "The quantity field must be a numeric value";} ?>

It's funny I have tried every way I can think of to get rid of the warning but it won't go away unless I completely turn off the display errors property in the configuration. Although the application works perfectly from what I can see. I think it may be this line causing the problem? header("Location: http://bcthub.com/Form2.php"); I see no other way though of writing the code. Could I get some commentary on this? Thank You!

Form1.zip

Link to comment
Share on other sites

I've read the sticky and I've made an attempt at solving the problem using output buffering however it still is coming at me with the warning:

 <?phpob_start();session_start();  $productname2 = $_POST['productname2']; if (isset($_POST['countone'])){  if(empty($productname2)){echo "No product name was entered. Use the back button to go back to the form and try again.";}else if($productname2 != $_SESSION['productname']){echo "The product name does not match. The counter was not incremented. Please use the back button and try again.";}else{$sepysCounter = $_SESSION['sepysCounter'];$sepysCounter++;$_SESSION['sepysCounter'] = $sepysCounter;header("Location: http://localhost/Form2.php");}} if (isset($_POST['resetbutton'])){$_SESSION['sepysCounter'] = 0;header("Location: http://localhost/Form2.php");} ob_end_flush();?>

Edited by sepoto
Link to comment
Share on other sites

I can assure you that as I view my files in Notepad++ on Windows 8 right now that there is no line break before the opening tags in any of my files however I can tell you that the version of PHP provided by my hosting provider is quite old and if I remember correctly is some release of PHP 5.2. Also I can tell you that on my development machine running PHP 5.4 xammpp configuration with display errors on in the php.ini the warning does not appear. PHP 5.4 is winning.

Link to comment
Share on other sites

Your server probably using "implicit flush", so thus it is outputting anyway.check the setting

Link to comment
Share on other sites

The error message tells you exactly where the problem is. It includes the filenames and line numbers for where the output was sent that caused the headers to get sent, and where the line was that tried to send a header after they were already sent. There's no reason to guess.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...