0

I need the client(customer) ip address of the browser.

This is the client page in php

<?php $xml_request = '<XMLRequest> <RequestType>ServiceRequest</RequestType> <RequestLogin>test</RequestLogin> </XMLRequest>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://testserver.com/test_xml/request.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_ENCODING,'gzip'); curl_setopt($ch, CURLOPT_POST, true ); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_request); echo curl_exec($ch); curl_close($ch); ?> 

This is my server page 'http://testserver.com/test_xml/request.php' in php

$service_request = file_get_contents('php://input'); echo 'Client IP Address: '. $_SERVER['REMOTE_ADDR']; 

But here its 'ECHO' my own server IP.

How i get the client browser IP to my server

2
  • Might want to look into stackoverflow.com/questions/11452938/… Commented Jun 22, 2015 at 13:37
  • 1
    Is that because you are testing this on the same PC as the server so client and server are both on the same IP address?? Commented Jun 22, 2015 at 13:39

4 Answers 4

2

Your're doing http request from your own server, that's why you get your server IP. To solve your problem you have to make changes in client page (eg. add additional parameter to XML Request or add custom header with client IP address)

Thank you.

Sign up to request clarification or add additional context in comments.

Comments

1

Are you hosting the website? Then it would show your own IP, when you viewed the website.

Comments

0

It will not work like that because you call the Server page from your client page, which both sit on your server and use PHP. So in your scenario the server is asking itself for his IP address (client & server are the same).

You could put $_SERVER['REMOTE_ADDR'] on your client page. But I also don't understand why you have a 'client' and a 'server' page both written in PHP and one calls the other with curl. It seems like horrible practice.

Comments

0

As answered by Jumes, you are using the correct Server variables. If you run your script from your server console [or by some other method] , your server Ip address will show up.

You may want to try running the client script from different machines [having different public IP addresses] to see a visible difference.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.