简体   繁体   中英

How to set X-Forwarded-For in PHP to sent client IP with simplexml_load_file

We have got the client real IP behind the proxy using X-Forwarded-For.

But now the issue is that when we are calling a web service using simplexml_load_file, the server hosting the web service gets the IP of our server and not the real client server.

So we need a way to set the IP in X-Forwarded-For header so that the webservice gets the IP of the client that means it will feel that the client IP has called the webservice.

One possibility would be to start using curl for communication with the web service, so that you'd be able to set the header value

$ip = '123.123.123.123'; // your client's IP Address
curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip",
                                            "X_FORWARDED_FOR: $ip"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM