hwo to redirect users depending on their country in php (with maxmind geoip) ?

Discussion in 'PHP' started by iglow, Dec 14, 2009.

  1. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Exactly as mentioned i have trouble wit hthat. I want to use the maxmind geoip base in php so that when user comes to my aaa.com then it checks if hes from .be .fr .ca and puts him on aaa.com/1.htm, if from .uk .au .us to aaa.com/2.htm anf if from other place tio aaa.com/3.htm [or .php doesnt matter here]
    Im sure its simple but somehow i cant code it. Would love the help of some expert ;)
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
  3. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    im reading that but looks complex to me, im not so good with php [i can edit simple parts but mainly i need more 'step by step' info.
    cant i just upload the files of geoip and put 2-3 pages of php code that will read them and make use of them? this looks a bit too complex with those shell commands

    thanx
     
  4. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    I have never heard of Geo IP extension of PHP earlier. I came to know about it only after your question. I also have to go through it to know more about GeoIP. :)
     
  5. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    im sure it can be done in php just by uploading all the files [not even importing to mysql] and using 1-2 .php files - ive seen such thing, but i have no idea how to do it and my knowledge of php doesnt allow me it seems ;)

    happy i
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Search the Articles and you would see it here as well.
     
  7. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    shabbir ive searched and i found some similar stuff but not exactly o nthe topic. i found only blocking by country in .htaccess with using php. and thats totally not what i want to do :)

    @ venami and i couldnt edit the post abouve but i wanted to say im happy i shown u something new with my question :)
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  9. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    hey yes ive seen but the modification seems not that obvious,
    have a look:

    Code:
     
    [LEFT][COLOR=#000000][B]<?php[/B][/COLOR]
    
    [COLOR=#808080][I]// include functions[/I][/COLOR]
    [COLOR=#B1B100]include[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"geoip.inc"[/COLOR][COLOR=#66CC66])[/COLOR];
    
    [COLOR=#808080][I]// read GeoIP database[/I][/COLOR]
    [COLOR=#0000FF]$handle[/COLOR] = geoip_open[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"GeoIP.dat"[/COLOR], GEOIP_STANDARD[COLOR=#66CC66])[/COLOR];
    
    [COLOR=#808080][I]// map IP to country[/I][/COLOR]
    [URL="http://www.php.net/echo"][COLOR=#000066]echo[/COLOR][/URL] [COLOR=#FF0000]"IP address 62.149.130.132 located in "[/COLOR] . geoip_country_name_by_addr[COLOR=#66CC66]([/COLOR][COLOR=#0000FF]$handle[/COLOR], [COLOR=#FF0000]"62.149.130.132"[/COLOR][COLOR=#66CC66])[/COLOR] . [COLOR=#FF0000]" (country code "[/COLOR] . geoip_country_code_by_addr[COLOR=#66CC66]([/COLOR][COLOR=#0000FF]$handle[/COLOR], [COLOR=#FF0000]"62.149.130.132"[/COLOR][COLOR=#66CC66])[/COLOR] . [COLOR=#FF0000]")"[/COLOR];
    
    [COLOR=#808080][I]// close database handler[/I][/COLOR]
    geoip_close[COLOR=#66CC66]([/COLOR][COLOR=#0000FF]$handle[/COLOR][COLOR=#66CC66])[/COLOR];
    
    [COLOR=#808080][I]// print compulsory license notice[/I][/COLOR]
    [URL="http://www.php.net/echo"][COLOR=#000066]echo[/COLOR][/URL] [COLOR=#FF0000]"<p> -- This product includes GeoIP data created by MaxMind, available from [url]http://maxmind.com/[/url] --"[/COLOR];
    
    [COLOR=#000000][B]?>
    [/B][/COLOR]
    [/LEFT]

    this code is suspossed to read the country code by using function include(). but now im not sure how to make working variabilities to redirect people from 9 countries [3 groups each for 3 countries] to 3 different adresses also not sure what kind iof redirect should be used.
    if somebody could have a look at this i would be pleased :)
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Redirect should be plan header if possible or else could be anything you like but the 3 countries of 3 group looks very simple. Whats the issue there.
     
  11. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    in my php skills thats why i came here since people can code :) i know a bit but i do somethign wrong and this doesnt redirect as it should.
    im a blackhatter but im never on the code side in a team..

    can u help ?
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Header('Location: newurl');
     
  13. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    okay but i mean how should i put those 3 inbetween? else if ?
     
  14. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I guess you need to look at basics of any programming first.

    if ( condition )
    {
    /// Redirect to country 1
    }
    else if( condition )
    {
    /// Redirect to country 2
    }
    else if ( condition )
    {
    /// Redirect to country 3
    }
     
  15. iglow

    iglow New Member

    Joined:
    Dec 13, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    yeah i know the else if, but i was wondering if its possible to make it shorter than that without so many else ifs [like i can once redirect each of 50 countries to 50 places].
    as i said im not a programmer, i have other skillz. just want to learn a bit [a bit not all] but not plain learning but on something that i could use - if u catch my drift. better to learn stuff while doing it than just reading how it works without examples.
     
  16. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    If you do not want all those IF ELSE blocks, then put the entries in a database table and you can do a SELECT to get the required URL for a given country.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice