Solved

Error: "Header info already sent"

Posted on 2016-07-30
9
37 Views
Last Modified: 2016-08-01
I know what the error means but I can't see it in the attached code.
I'm getting the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/langsyst/public_html/Lansco/Company_Display.php:30) in /home/langsyst/public_html/Lansco/Company_Display.php on line 46

Line 30 is "<?php

The include statements at the top have no "echo"

I've attached the code.
Company_Display.php
0
Comment
Question by:breeze351
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 4

Expert Comment

by:Branislav Borojevic
ID: 41735974
You seem to have a whitespace after the closing
?>

Open in new window

.

Please remove the whitespace and re-test.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41735998
Header ("Location:$work"); can not be used after you have sent HTML content.  After all, it is a header and must come before any content.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41736009
0
 

Author Comment

by:breeze351
ID: 41736010
Where is the HTML content?  I don't see it.  I know that's the problem.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41736012
Lines 12-29 are all output - everything from <!DOCTYPE....> to the blank space after the <body> tag are all output. Just move it down to the bottom of that same file.
1
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41736016
Maybe try it like this:
<?php


ob_start();


// **************************************************************
// * Company_Add.php                                            *
// * Keyin screen for company add/edit.                         *
// **************************************************************
// * Ver    By     Date       Description                       *
// * 4.01   GJJD   04/25/16   Modify for PHP 5.6                *
// **************************************************************
	include 'Session_Start.php';
	include 'db_connect_inc.php';
?>	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Contact Display</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<link rel="stylesheet" type="text/css" href="NewCss.css">
    <script type='text/javascript' src='//code.jquery.com/jquery-2.1.3.js'></script>
    <script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2014/10/jquery.maskedinput.js"></script>

<script type="text/javascript">
		function MM_goToURL() 
		{ 
			var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
			for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
		}
</script>
</head>   
<body>	

<?php
	include 'Check_Login.php';
	include 'Prog_Count_inc.php';
	$Display_Phone = $_SESSION['South'];
	$_SESSION['South'] = str_replace("/", "", $_SESSION['South']);
	$_SESSION['South'] = str_replace("(", "", $_SESSION['South']); 
	$_SESSION['South'] = str_replace(")", "", $_SESSION['South']); 
	$_SESSION['South'] = str_replace(" ", "", $_SESSION['South']); 
	$_SESSION['South'] = str_replace("-", "", $_SESSION['South']); 
	$_SESSION['South'] = trim($_SESSION['South']); 
	$work = strlen($_SESSION['South']);
	if ($work != 10)
	{
		$_SESSION['Message'] = "Invalid phone number entered!";
		$_SESSION['Error'] = "Y";
		$work = $_SESSION['Last_Page'];
		Header ("Location:$work");
		exit;
	}
	$Data = $_SESSION['South'];
	include 'menu_inc.php';

Open in new window

Ref:
https://www.experts-exchange.com/articles/4423/Warning-Cannot-modify-header-information-headers-already-sent.html
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41736024
Hello????  You can NOT put Header ("Location:$work"); (line 51 in Ray's code) after any HTML content has been sent!!!!  It is an HTTP header, it MUST come before any content is sent.  That is the reason for the error message.

For reference:  http://php.net/manual/en/function.header.php
2
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41736058
Further to Dave's point, that is the purpose of using ob_start().  This is all explained in the article, but to recap: ob_start() in this usage stops the server from sending the output to the browser.  Instead, the browser output is captured and held in a PHP buffer until there is another deliberate PHP buffering event, or the end of the script, with implicit ob_end_flush().  Only then will the browser output be released and sent.  Thus the PHP header() function can proceed without the interference of a prior browser output event.
0
 

Author Closing Comment

by:breeze351
ID: 41737859
Got it.
Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now