1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Q?] GEO IP Script Problem! Help!

Discussion in 'Black Hat SEO' started by satyawrat, Feb 24, 2010.

  1. satyawrat

    satyawrat Jr. VIP Jr. VIP

    Joined:
    Jul 8, 2009
    Messages:
    924
    Likes Received:
    1,182
    Occupation:
    Hustler
    Location:
    Gurgaon
    Home Page:
    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...
     
  2. booster2ooo

    booster2ooo Junior Member

    Joined:
    Jan 17, 2009
    Messages:
    104
    Likes Received:
    30
    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)
     
    • Thanks Thanks x 1
    Last edited: Feb 24, 2010
  3. satyawrat

    satyawrat Jr. VIP Jr. VIP

    Joined:
    Jul 8, 2009
    Messages:
    924
    Likes Received:
    1,182
    Occupation:
    Hustler
    Location:
    Gurgaon
    Home Page:
    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
     
  4. booster2ooo

    booster2ooo Junior Member

    Joined:
    Jan 17, 2009
    Messages:
    104
    Likes Received:
    30
    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).
     
    • Thanks Thanks x 1
  5. satyawrat

    satyawrat Jr. VIP Jr. VIP

    Joined:
    Jul 8, 2009
    Messages:
    924
    Likes Received:
    1,182
    Occupation:
    Hustler
    Location:
    Gurgaon
    Home Page:
    Okay going to to try it right away, will report back!