Solved

Error: "Header info already sent"

Posted on 2016-07-30
9
44 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 83

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:breeze351
ID: 41736010
Where is the HTML content?  I don't see it.  I know that's the problem.
0
 
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 109

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 83

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 109

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 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