Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i know this has a million answers here, but what do you do when after all this you still get the Proxy's IP instead of the client's? i have tried a lot of solutions, but none of them work. I always end up with Proxy's IP instead of the client's. any help?
the JS i tried to use:

XML
<script type="application/javascript">
  function getIP(json) {
  // document.write("My public IP address is: ", json.ip);
    var ip=json.ip;
    document.getElementById('IPaddr').value = json.ip;

      }
function LoadJsonDataFunction()
{
  $.getJSON("https://api.ipify.org?format=jsonp&callback=getIP", function(obj) {
    $.each(obj.ip, function(key, value){
      $("IPaddr").append(value.ip);
    });
  });
}
 </script>
// <script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>


the hidden HTML field's value:
<input type="hidden" name="IPaddr" value="" /> 


but the $_POST['ip'] is always NULL.
Posted
Updated 24-Jul-15 4:40am
v2
Comments
Mohibur Rashid 25-Jul-15 13:17pm    
I am not going to tell you about ip address but your jquery statement:
$("input[name='IPaddr']").val(value.ip);

Learn how proxy servers and TCP/IP work.

It's IMPOSSIBLE to get the client IP because it's never sent to you. The client from your servers point of view IS the proxy!

Proxy servers don't talk to your server and say "Hey, I'm a proxy making this request on behalf of this client". It says "Hey, I'm your client, this is my request".

See the difference? This is why you cannot get the real client IP.
 
Share this answer
 
v2
Comments
RevathySanthanam 24-Jul-15 10:26am    
i understand that. but i tried with JS too (as commented to above solution). is it not possible even then?
Dave Kreskowiak 24-Jul-15 13:58pm    
What part of "IMPOSSIBLE" do you not understand? It already told you why it will never work no matter what you do.
[no name] 24-Jul-15 10:30am    
Clear Explanation, thank you for this, my small 5.
The reason you can't find a solution is because there is none, that is just how the internet works. You'll need to capture the IP at the client (somehow) and send that to the server (somehow). If you are looking for a server-only solution then there isn't one, and that won't change no matter how many times this question is asked.
 
Share this answer
 
Comments
RevathySanthanam 24-Jul-15 10:26am    
Right, I read that the client's IP doesnt even reach the server, so I tried to use Javascript to access API's data to get client IP but I am unable to get that value from Javascript into my HTML form i'm using. I tried to give it as value to a hidden input, echo using script tag, all the time I got an empty result. The JS variable value expires by the time it comes to the HTML body. Anyway I can get that JS var into PHP or HTML?
F-ES Sitecore 24-Jul-15 10:35am    
I'm not aware of any way to get this data via javascript either, you'd have to update your question to include any code you are currently using.
RevathySanthanam 24-Jul-15 10:41am    
i just did that. could u maybe have a look?
F-ES Sitecore 24-Jul-15 10:56am    
You update a hidden field using $("#IPaddr").val(value.ip) however that still isn't going to work, all that is happening is that the api you are calling is doing the same "Get request IP address" code on the server, so you're still going to get the proxy's IP address. The thing that reads the IP is still happening on the remote server even though you are instigating that call via the client.
RevathySanthanam 24-Jul-15 11:01am    
but when i just try to display that value from the JS, i get the required IP. now the issue is, to gte that value from JS and use in my other part of the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900