Jump to content

[SOLVED] script and html conflict in trying to create a header.


br549

Recommended Posts

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 the html page and the script both trying to create a page header. 

 

The result is.. when the script executes.  I get an error.

 

I'm a weak coder and this is driving me crazy.  I've read header section in this forum. And it's a bit complicated for me.  please tolerate my "inability."

----------

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>

 

The script is a bit more complicated.

 

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

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

</head>

 

 

Link to comment
Share on other sites

I forgot the code:

 

<?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();
} 
}

?>

Link to comment
Share on other sites

And the error is?

Please tolerate me... I'm not the smartest person in the world.  (But I try hard)

 

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
Link to comment
Share on other sites

It means that you are outputting content to the browser before trying to send a header.

 

ok, please tolerate me a little bit more.

When I did this work, I literally had someone standing over my shoulder talking me through it.

 

So here is a real noob question.  What do I need to do to correct this ?

Link to comment
Share on other sites

Make sure there is no output before any headers are sent.

 

even spaces.

 

so ensure that this is the first thing in your script.

 

<?php require('geoipscript.php'); ?>

 

no spaces before the <?php, nothing is echoed before any header() calls.

 

That is assuming that geoscript.php is the script you posted the code for.

 

Also just noticed, why does index.html have php in it?

Link to comment
Share on other sites

Make sure there is no output before any headers are sent.

 

even spaces.

 

so ensure that this is the first thing in your script.

 

<?php require('geoipscript.php'); ?>

 

no spaces before the <?php, nothing is echoed before any header() calls.

 

This is where I'm having the problem.  The <?php require('geoipscript.php'); ?> is the very first thing and there are no spaces.

If there is something there.. I can't see it.

 

That is assuming that geoscript.php is the script you posted the code for.

 

Also just noticed, why does index.html have php in it?

 

Index.html is an html page.  I use the <?php require('geoipscript.php'); ?> at the top of this page to call the script geoipscript.php

Link to comment
Share on other sites

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.

 

:wtf:

 

This ?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Link to comment
Share on other sites

Oh lord love a duck.

 

I did some research and found out what that was.  (Like I said, I'm not the smartest person in the world)

 

Alright I origionally did an edit in notepad.  Which probably put the "unseen" bom there

 

But can I ask,

will including a signature Unicode BOM when I do my save on the files cause similar problems ?

 

Link to comment
Share on other sites

Problem solved !

And what a nightmare it was...

 

So that others can learn from my mistakes.. Here is the story of how an amateur messed up.

 

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 not the smartest person in the world and 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."  ((Seems pretty stupid if you ask me.  I would expect a text editor should show me everything on the page.))

 

Well, I downloaded a programe called "Topstyle lite".  And like throwing flower on the Invisable man... boom!  My invisable characters showed up.  I deleted them and everything came back online.

 

 

Thank you to this forum and everyone in this thread that has helped me.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.