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

Could somebody share php code for geo-reditect script?

Discussion in 'General Programming Chat' started by SpecialOne, Aug 9, 2015.

  1. SpecialOne

    SpecialOne Registered Member

    Joined:
    Jan 12, 2011
    Messages:
    65
    Likes Received:
    21
    Does anybody have free geo-redirect script to share? I tried maxmind shared on here in this thread , but it is outdated and it doesn't seems to work. I see there is maxmind free geolite2 database. Could somebody implement new database and share php code? https://dev.maxmind.com/geoip/geoip2/geolite2/
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    970
    Likes Received:
    678
    Occupation:
    Web/Bot Developer
    Here you go:
    Code:
    https://maxmind.github.io/GeoIP2-php/
     
  3. davids355

    davids355 Jr. VIP Jr. VIP

    Joined:
    Apr 25, 2011
    Messages:
    9,831
    Likes Received:
    7,436
    Home Page:
    pretty good guide here also:
    https://github.com/maxmind/GeoIP2-php

    Think it is just a case of uploading those files to your site and then using their php script which is ready to go.

    It will work with the free databases provided by maxmind, or you can sign up for their realtime data service which is about $20 per 200,000 queries...
     
  4. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,229
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Use the search button, asked many times and answered many times!
     
  5. SpecialOne

    SpecialOne Registered Member

    Joined:
    Jan 12, 2011
    Messages:
    65
    Likes Received:
    21
    I already did searched whole Internet. Old geo-redirect scripts don't work anymore because maxmind changed something. If you are so smart then tell me one thread on BHW where could I find working script?
     
    Last edited: Aug 9, 2015
  6. SpecialOne

    SpecialOne Registered Member

    Joined:
    Jan 12, 2011
    Messages:
    65
    Likes Received:
    21
    Thx, but I do not know how to use composer. Why I need to download desktop application "composer" to code something when I actually need only redirect script on my server not on my PC. Also there is no geo-redirect script.

    I think this is the same as MrBlue shared. You say use their script, but that script is not even geo-redirect script. From the code I could see that it is detecting users IP location. There is no code for geo-redirect.
     
  7. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    970
    Likes Received:
    678
    Occupation:
    Web/Bot Developer
    Composer is a dependency manager for PHP. It's not required that you use composer to download and use the script but it does make things easier.

    There certainly is a sample GEO-IP script. Did you not see the "City Example" just below on the same page?
     
  8. SpecialOne

    SpecialOne Registered Member

    Joined:
    Jan 12, 2011
    Messages:
    65
    Likes Received:
    21
    I just need simple country geo-redirect script. For example:

    - First detect users country

    - if user is from US redirect him to website 1
    - if user is from CA redirect him to website 2
    - if user come from rest of the world redirect him to website 3

    That is simple redirect script I need. That "City Example" you gave me is detecting country, city, latitude, longitude etc. I just need simple country redirection script, but don't know how to do that.
     
    Last edited: Aug 9, 2015
  9. dadiaar

    dadiaar Newbie

    Joined:
    Mar 7, 2013
    Messages:
    31
    Likes Received:
    9
    Occupation:
    Ecommerce
    Location:
    China
    Good morning SpecialOne

    I already sent you a solution replying your PM.

    Option 1 is easy to implement, but if you want the better option 2 and need help, contact me.

    Have a nice day.

     
  10. h123er2

    h123er2 Newbie

    Joined:
    Jun 23, 2011
    Messages:
    3
    Likes Received:
    0
    If you go to my blog webdevtown . c0 m and search for 'location' you'll find exactly what you're after. It's a script I released a while ago that uses an API to detect country and redirect user.

    If anything else, lemme know.