Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error: "Header info already sent"

Posted on 2016-07-30
9
Medium Priority
?
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

721 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