SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: IP Based Image

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IP Based Image

    Hi, i have a banner area on my website where i would like to display an image. I would like to display a different image in the banner area, depending on a users' location.

    I have 4 different images:

    01 - usa_banner.jpg (default)
    02 - europe_banner.jpg
    03 - uk_banner.jpg
    04 - australia_banner.jpg

    If a user views the site from a country outside of the top 4 areas, then i would like to display the default usa_banner.jpg image.

    I have created my site using codeigniter. What is the best way to work out the IP ranges etc. Any advice on this would be greatly appreciated. Thanks in advance...

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    Hi there,

    I would use a third party service to do this, such as http://www.hostip.info/

    PHP Code:
    <?php
    $country 
    '';
    $ip $_SERVER['REMOTE_ADDR'];

    if (!empty(
    $ip)) {
      
    $country file_get_contents('http://api.hostip.info/country.php?ip='.$ip);
    }
    ?>
    Then you can use a simple if else statement to do the rest.

    HTH
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, thanks... how reliable are these 3rd party services...

  4. #4
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    I've no direct experience of this one, but a quick WHOIS look-up, shows that the domain has been registered since 2003.
    That's quite a good sign.

    Saying that, if you don't pay for it, you can't be disappointed if it goes away at some point ...
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    1,863
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    <?php
    //Kyle Wolfe
    echo devBlog("My Dev Notes");

  6. #6
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Has anyone ever used MaxMind?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •