Jump to content
sepoto

Warning: Can not send headers - Headers Already Sent

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

There's a line break before your opening <?php tag. That counts as output.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

implicit_flush is set to off on both systems 5.2 @ HostGator and 5.4 @ localhost.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...