0

I'm in the process of streamlining my website, and want to display elements on the site specific to my ip address that the public cannot see. I have a static IP address, which is half the battle.

After an intense google session, I have found a snippet of code that pulls my IP and throws an alert. if feel this is the closest to my goal, but unsure how I can adapt it. For example, if IP address is 'this' show div, if not hide div.

// Find IP, throws alert    
$.getJSON("http://jsonip.com?callback=?", function (data) {
alert(data.ip);
});

// My Attempt - Hide menu if IP matches
var data = '00.00.00.000';
$('#Menu').each(function() {
if (this.data == '00.00.00.000') {
  $(this).addClass('hide-me');
}

Any advise or suggestions would be a massive help.

Thanks, Ant

  • 4
    Don't do it! If it's sensitive data ALWAYS, I repeat ALWAYS hide it server sided. A potential hacker could just open the inspector, and execute the JavaScript himself. – Esli Stavenga Apr 24 '19 at 10:54
  • 3
    Ideally, this should be sent server side, where you can intercept the request headers and IP. Set a simple flag which can be used to hide / show data. Or more secure, restrict the data to be rendered from server side itself, and the client would be agnostic of what data to be shown. – Easwar Apr 24 '19 at 10:55
  • Thank you for your swift response! I will look into delivering this server side, although it's not sensitive data I would still like to work towards best practice. – Anthony Whitefield Apr 24 '19 at 11:06

0 Answers0