...

View Full Version : Can't stop outputting content to the browser before trying to send a header.



looser
10-25-2009, 10:56 PM
I have an error is occurring because of an html webpage with a "php require" at the top of the page calling a script.

Somehow I'm having a problem with sending content to the browser before I create a header. The result is.. when the script executes. I get an error.

I'm a weak coder and this is driving me crazy. Everything I read is a bit complicated for me. please tolerate my "inability" I tend to need to be hand held.

The error:

Warning: Cannot modify header information - headers already sent by (output started at /home/host/public_html/website.com/index.html:1) in /home/host/public_html/website.com/geoipscript.php on line 49


The HTML page.


<?php require('geoipscript.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>the site</title>

<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

--------
The script


<?php
/*
April 4, 2009 - Script looks up the country code and state name of a visitor's IP address
Visitors are given access depending on their geographic location

*/

// VARIABLES
$host='localhost'; //Enter your host here within the quotes
$username='thename'; //Enter your username of the mysql database
$passwd='password2enter'; //Enter the password for that username
$database='AAA1'; //This is where you database info is stored.
$badurl='http://badurl.com'; // This is where you will be redirected if people are BAD
$goodcountry = array('BE'); // Must be universal country code
$goodregions = array('Bruxelles'); // Must be FULL name


// PROCESS
function Dot2LongIP ($IPaddr) {
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}

$db = mysql_connect($host,$username,$passwd) or die ("mysql_connect() failed: " . mysql_error());
mysql_select_db($database,$db) or die ("mysql_select_db() failed: " . mysql_error());

$ip = Dot2LongIP($_SERVER['REMOTE_ADDR']);
$result = @mysql_query ("SELECT country_code, state_name FROM find_location WHERE '$ip' <= ip_to and '$ip' >= ip_from limit 1");
while ($row = @mysql_fetch_array ($result)) {
$country = $row[0];
$region = $row[1];
}

if ($_GET['geo_debug']=="true") { // if degugging, just show what would happen
echo "IP: ".$_SERVER['REMOTE_ADDR']."<br>Long: $ip<br>Country Code: $country<br>Region: $region<br>Allow? ";
if (!in_array($country, $goodcountry) && !in_array($region, $goodregions)) {
echo "No";
} else {
echo "Yes";
}
} else { // if not debugging, redirect them if needed
if (!in_array($country, $goodcountry) && !in_array($region, $goodregions)) {
header("Location: $badurl");
exit();
}
}

?>

CFMaBiSmAd
10-25-2009, 11:44 PM
Your index.html page has been saved with the UTF-8 BOM (Byte Order Mark) characters at the start of the file. You need to save it without the BOM.

looser
10-26-2009, 11:26 AM
Your index.html page has been saved with the UTF-8 BOM (Byte Order Mark) characters at the start of the file. You need to save it without the BOM.

Problem solved !

I do quick edits all the time on my sites using Notepad. Until recently, I never had a single problem. But yesterday, problems struck with vengence.

I'm a real hack at any coding. Until a few hours ago, I never even heard of "UTF-8 BOM." I had no clue in the world there was "Invisable characters."

So , I found and downloaded a programe called "Topstyle lite". And boom baby! My invisable characters showed up. I deleted them and everything came back online.


Thank you very much for the help!

Lamped
10-26-2009, 12:31 PM
I hope this won't be perceived as advertising, as it's not... If it is, mods, feel free to delete it.

I use Eclipse / Aptana for most of my projects, but for "quick stuff" I use Programmers Notepad (a friend wrote it, so maybe I'm biased)

http://www.pnotepad.org/

No more notepad, no more BOM blues.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum