Avatar of breeze351
breeze351
 asked on

Error: "Header info already sent"

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
PHP

Avatar of undefined
Last Comment
breeze351

8/22/2022 - Mon
Branislav Borojevic

You seem to have a whitespace after the closing
?>

Open in new window

.

Please remove the whitespace and re-test.
Dave Baldwin

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.
gr8gonzo

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
breeze351

ASKER
Where is the HTML content?  I don't see it.  I know that's the problem.
gr8gonzo

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.
Ray Paseur

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

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
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
breeze351

ASKER
Got it.
Thanks