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

GEOIP Question: How do i keep people from UK on my site and send the rest elsewhere

Discussion in 'General Programming Chat' started by Inception_AC, Oct 13, 2015.

  1. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP

    Joined:
    Feb 16, 2011
    Messages:
    1,964
    Likes Received:
    1,406
    Im currently working on a few projects, I want to keep people from the UK (GB) on my site and send the rest to an exit page, Does anyone have the code for this?

    Looked on google but could only find geoip redirects via php and i need it to stay on my html page

    thanks
     
  2. ChanzGrande

    ChanzGrande Elite Member

    Joined:
    Feb 16, 2008
    Messages:
    2,484
    Likes Received:
    1,172
    Occupation:
    Accountant
    Location:
    Northern Woods Counting Money
    I think you are trying to utilize elements of code and scripting that require PHP functionality. You could consider setting the browser check up in a php file, and redirecting UK traffic to the appropriate HTML file.

    That's how it's done - it's not about NOT putting php elements in a .html file. It's about properly using a .php file to redirect the correct traffic to the correct .html file.

    You may be able to find some rudimentary html5 coding to utilize as a base to create a javascript based geo-detection and redirection code snippet - but that's quite a bit harder than simply implementing the known and working PHP based solutions.
     
    Last edited: Oct 13, 2015
  3. Sarseo

    Sarseo Regular Member

    Joined:
    Jun 30, 2015
    Messages:
    205
    Likes Received:
    22
    Hire somboday to creat Script for you
     
  4. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP

    Joined:
    Feb 16, 2011
    Messages:
    1,964
    Likes Received:
    1,406
    I already have the php version, but i just need to emplement it so that uk visitors stay and the rest go onto a different site.

    Hopefully I will find it, ive seen the html version of it before
     
  5. blackcommoner

    blackcommoner Registered Member

    Joined:
    Jun 7, 2015
    Messages:
    63
    Likes Received:
    5
    Try to use any javascript plugin if you want to use html.
    A nice plugin : http://www.geoplugin.com
    Knock me if you face any problem to implement.
     
  6. kunnu

    kunnu Regular Member

    Joined:
    Jun 28, 2015
    Messages:
    217
    Likes Received:
    34
    Home Page:
    For redirect you don't need to use html or php.

    Just use .htaccess

    There is also a website which allow you to select allowed country and disallow all.

    .htaccess file
    allow from UK-IP.x.x/24
    allow from UK-IP/24 #(/24 Whole IP Range)
    deny from all #(it will deny all IPs which is not belong to allowed UK IPs.

    Hope you understand.
     
  7. roadhamster

    roadhamster Regular Member

    Joined:
    Mar 12, 2012
    Messages:
    335
    Likes Received:
    242
    Coded a little piece for you:
    PHP:
    <?php

    $geodata
    =json_decode(file_get_contents("http://www.telize.com/geoip/" $_SERVER['REMOTE_ADDR']),1);

    if(
    $geodata['country_code']<>"GB")
        {
        
    header("Location: your_redirect_url.whatever"
        exit();
        }
        

    ?>
    Replace the your_redirect_url.whatever with your url to redirect non-UK visitors.
    Put it in your html file, in front of the actual html code, rename it to .php and you're good to go. Some disadvantages: this is relying on a free web-api from a third-party, if that site site is down, your screwed.

    Another option is to download the maxmind geoip database to your server and create a php script.
     
    Last edited: Oct 20, 2015