Grow your CSS skills. Land your dream job.

Display Content Based on IP Address

  • # September 22, 2010 at 1:09 pm

    Hi everyone! I’m currently interested in displaying a quick line or two of copy if a visiter’s IP address falls between a certain range. Do any of you have any resources or ideas of how I can go about it?

    I’d like to use JS for this. I’d imagine I can use JS to detect the IP then use an IF statement to display said content. I’m pretty new to JS and is the reason why I would love some help from ya’ll :)

    Any help is MUCH appreciated. Thnx!

    # September 22, 2010 at 4:47 pm

    yeah… all right ok … it can be possible but there is more than just js for this to work if u want to display content depending on country…etc… but if you know the IP address of the person then is much easier here is a php Snippet to get the job done…

    < ?php
    /*
    this Snippet allows you to display content "ONLY" to a visitor from
    a specific IP addresses in a page.
    Change the $allowed "value" to the IP address you want.
    */
    $allowed = '00.000.000.000';
    $userip = $_SERVER;
    if($userip == $allowed){
    echo "This content is only viewed by the IP address you chose...";
    }
    ?>
    # September 22, 2010 at 6:51 pm

    Thanks man, not exactly what I was looking for, but it’s good to know the php side of things.

    I’m really trying to do this with JS. I’m also trying to do a range of IP addresses.

    Thanks for your input!

    # September 22, 2010 at 9:29 pm

    As far as I know JavaScript can’t detect IP address’s, it is client side remember?

    # September 24, 2010 at 4:30 pm

    # August 1, 2012 at 1:46 am

    You can find the IP address and the location details using ip-details.com.
    It gives your current ip address and location details with the location
    map with latitude, longitude coordinates.

    # May 16, 2013 at 6:38 am

    use the javascript service provided by geolify.com

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".