Onclick point to function with $ _SERVER

1

Due to an obscure system need, when clicking a button, I need to know the IP that triggered the same to direct the correct page. With $_SERVER['REMOTE_ADDR'] I have this information. But how could I pass this on to a JS? More or less this way:

document.getElementById('LIMPAR').onclick = function() {
      if ($_SERVER['REMOTE_ADDR'] == 'XXX') {
         location.href = '1';
      } ELSE {
         location.href = '2';
      }
} 

Testing the logic above, I did not succeed. Any suggestions?

    
asked by anonymous 05.09.2016 / 20:45

1 answer

1

You are trying to access a context variable from PHP , server, on the client side, javascript .

Try something like this:

document.getElementById('LIMPAR').onclick = function() {
  var ip = '<?php echo $_SERVER['REMOTE_ADDR']; ?>';
  if (ip == 'XXX') {
    location.href = '1';
  } ELSE {
    location.href = '2';
  }
}
    
05.09.2016 / 20:59