0

I am making an IP approval system for my website, and I would like to, if the user has an IP address on the banned list, be redirected to banned.html on my site. I would like some JavaScript code for the head section on my website.

I know that a javascript redirect is...

window.location="banned.html";

But I am not sure of a function that returns the IP.

What code would I put in my head section to do this?

EDIT: This is not a duplicate, as it is asking how to incorporate a redirect into the IP detection.

EDIT: You can use JSON for the IP:

$(document).ready(function () {
    $.getJSON("http://jsonip.com/?callback=?", function (data) {
        console.log(data);
        alert(data.ip);
    });
});

but how do I incorporate a redirect into this, based on if an IP is found on a list.

  • Most of the sites might be having dynamic IP's, what would you do in that case? – David R Sep 01 '16 at 06:31
  • are you allowed to use ajax? – Shridhar Sep 01 '16 at 06:32
  • @shridhar yes I can use ajax –  Sep 01 '16 at 06:33
  • 2
    Possible duplicate of [How to get client's IP address using javascript only?](http://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript-only) – StudioTime Sep 01 '16 at 06:39
  • 2
    Using javascript to enforce your ban is not recommended, users can easily turn off the javascript on their end. You should do your checks on the server side. – Itay Gal Sep 01 '16 at 06:41
  • @ItayGal it is just to stop some kids from spamming my website - they probably don't know how to turn off javascript! –  Sep 01 '16 at 06:42
  • @DanielHarrin Kids are those people, who know the most about computers ;) – Herr Derb Sep 01 '16 at 06:57
  • @HerrDerb yeah but these kids I am banning have nothing better to do with their time than swear in the comments of my website –  Sep 01 '16 at 06:58

0 Answers0