[Q?] GEO IP Script Problem! Help!

Buzzika

Supreme Member
Joined
Jul 8, 2009
Messages
1,446
Reaction score
1,678
I wanted a geo-ip redirection script for one of my projects.
I searched BHW and got the script and db of the ips.
I used the exact same script. but i get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/janghu07/public_html/getip.php:2) in /home/janghu07/public_html/getip.php on line 20


PHP:
<?php
 
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
 
$country_code = geoip_country_code_by_addr($gi, "$ip");
 
// Country name is not used so commented
// Get Country Name based on source IP
//$country = geoip_country_name_by_addr($gi, "$ip");
 
geoip_close($gi);
 
switch($country_code)
 
    {
        case "US": header("Location: http://google.com/"); break;
        default: header("Location: http://www.yahoo.com/");
}
?>
The ip db and Maxmind API were transferred to the server in Binary mode.

I remember setting this up in 5 minutes when i was using jumpline hosting. Now I am with Hostgator..
Can hostgator be a problem?
I need help...
 
Read PHP doc dude... header or sessions functions need to be passed BEFORE any outputed text. (Here, you output something line 2 and header() is line 20 so header doesn't work)

Edit:
PHP.net said:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
source: http://be.php.net/manual/en/function.header.php

Edit #2:
If you use UTF-8 files format, use UTF-8 without BOM or you'll get the same problem (output at line 0)
 
Last edited:
Read PHP doc dude... header or sessions functions need to be passed BEFORE any outputed text. (Here, you output something line 2 and header() is line 20 so header doesn't work)

Edit:

source: http://be.php.net/manual/en/function.header.php

Edit #2:
If you use UTF-8 files format, use UTF-8 without BOM or you'll get the same problem (output at line 0)

Well, The file is in utf-8, but how to use utf-8 without bom?
What if i save it in ANSI?
thank you for your advice. As I have no experience with coding can you please tell me what corrections I have to make so the script works fine?

again thanks for your help
 
Move your PHP script at the BEGINING of the file

I don't think you've got problem with the BOM (as the error isn't on line 0). Anyway, for Windows users, you can convert file to UTF-8 without BOM using NotePad++ (Format -> Convert to UTF-8 without BOM).
 
Move your PHP script at the BEGINING of the file

I don't think you've got problem with the BOM (as the error isn't on line 0). Anyway, for Windows users, you can convert file to UTF-8 without BOM using NotePad++ (Format -> Convert to UTF-8 without BOM).
Okay going to to try it right away, will report back!
 
Back
Top