Pass jquery value to php

Asked

Viewed 386 times

0

I’m looking for a div from another page and putting 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 #ip_filter div on the index.php page is loaded into the #test div normally.

The content of this ip_filter div is an ip address of who accesses index.php. On my page I would like to put a condition in php that if the ip address (value that will be brought to div #test) 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 condition with javascript even, but the problem is that there are linux machines on the network using firefox browser and javascript disabled on these machines.

Is it possible to do this using php?

  • From what I understand you want to make the condition with php because javascript may be disabled, but the request with load uses javascript in the same way. o. o

  • True, I didn’t really take that into consideration. Actually what I want is to disable the input below and change the value of the placeholder if the ip that is in the div #test for x.x.x.x <div><input name="Try" type="text" id="Try" placeholder="Try" value="""?

  • Got it, answered...

2 answers

0

Good from what I understand is a simple check, 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 the value of the 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>
<input class="ip" type="text">

Problem

Javascript is a language client side, then important checks where Ip s are exposed, is not his work, but of a language server-side, If security is a big problem in your project, it is better to review your logic

0

Not. You cannot change the page via PHP after it has been sent by the server.

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

Updating:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.