Passing value from jquery to php

0

I'm looking for a div from another page and putting it in my:

My div:

  <div id="teste"></div>

script:
  <script type="text/javascript">
  $("#teste").load("http://www.home356.org/index.php #ip_filter");          
  </script>

With this script the result of the div #ip_filter in the index.php page is loaded into the div #teste normally.

The contents of this div ip_filter is an ip address of the person who accesses index.php. In my page I would like to put a condition in php that if the ip address (value that will be brought to div #teste) is x.x.x.x, do: echo="something". if not x.x.x.x, do: echo="something else."

I think it is possible to do this with javascript same, but the problem is that it has linux machines on the network using browser firefox and javascript disabled on these machines.

Is it possible to do this using php?

    
asked by anonymous 28.08.2017 / 19:55

2 answers

0

No. You can not change the page via PHP after it has been sent by the server.

This is possible on the client side (eg JS, jQuery).

Updating:

What you can do is load the page http://www.home356.org/index.php #ip_filter before the div , either include or another method, assign the IP to a $x any variable, make the necessary IFs and within div make a echo with the result.

    
28.08.2017 / 20:19
0

Good thing I understand is a simple verification, you want to receive the IP and if it matches the desired, do something or not.

Method Attr of J-query makes changes to tag properties and val changes value of same if it is input , example ...

$(document).ready(function(){
	
  var ipVerify = '20.0.255.255';
  var ip = '20.0.255.255'; // no seu caso o resultado do load
  
  if(ip == ipVerify){
  	$(".ip").attr('disabled', 'true');
  	$(".ip").attr('placeholder', 'try');
  	$(".ip").attr('id', 'try');
  }else{
  //caso for seja diferente
  }
  
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputclass="ip" type="text">

Problem

Javascript is a client side language, so important checks where Ip's are exposed, it's not their job, but a server-side language, if security is a big problem in your project, it's best to review your logic

    
29.08.2017 / 20:43