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

Need help with geo targetting

Discussion in 'General Programming Chat' started by Inception_AC, May 9, 2013.

  1. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Im looking to send visitors of my webpage to different parts of my websites based on there countries.

    the countries are

    united kingdom
    america
    ireland
    italy
    belgium
    sweden
    france
    new zealand
    south aftica

    how easy is this to do??

    thanks to all who help!
     
  2. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,290
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    • Thanks Thanks x 1
  3. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Thanks man!
     
  4. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Code:
    <?php/**
    * Case Study - GeoIP Redirection
    *
    * @version $Id$
    * @package geoip
    * @copyright © 2006 Lampix.net
    * @author Dragan Dinic 
    */
    require_once(”geoip/geoip.inc”);
    $gi = geoip_open(”geoip/GeoIP.dat”,GEOIP_STANDARD);
    $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    geoip_close($gi);
    if($country_code == ‘GB’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘CA’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘US’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘ZA’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘NZ’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘IE’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘SE’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘FR’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘NL’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    else
    {
    if($country_code == ‘AT’)
    {
    header(”Redirecting”);
    header(’Location: http://LINKHERE’);
    }
    ?>
    this gives me a Parse error: syntax error, unexpected ':' in /home/pennyauc/public_html/index.php on line 17

    can you help??

    Thanks
     
  5. natsirtdm

    natsirtdm Junior Member

    Joined:
    Jun 5, 2012
    Messages:
    121
    Likes Received:
    44
    don't see anything immediately out of place but might help if you used "switch" instead of that ugly if /else / if you have going on

    google php switch
     
    • Thanks Thanks x 1
  6. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Switch seems very difficult to use for switching to countries?
     
  7. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,290
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    get rid of those foreign chars in these lines:
    header('Location: http://LINKHERE');

    the ' are the problem, they aren't regular '
     
    • Thanks Thanks x 1
  8. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Parse error: syntax error, unexpected ':' in /home/pennyauc/public_html/index.php on line 17

    unexpected :
     
  9. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    its alright I got it cheers guys! used a simpler code :D
     
  10. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,290
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
  11. west13

    west13 Junior Member

    Joined:
    May 31, 2012
    Messages:
    173
    Likes Received:
    63
    Can you share it pls. I'm looking for smth like you have and my script gives some error also.