Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error: "Header info already sent"

Posted on 2016-07-30
9
Medium Priority
?
74 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 84

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 35

Expert Comment

by:gr8gonzo
ID: 41736009
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:breeze351
ID: 41736010
Where is the HTML content?  I don't see it.  I know that's the problem.
0
 
LVL 35

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 111

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 84

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

963 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