简体   繁体   中英

How To Forward Client IP Address Using Apache or PHP

Hello I was wondering is it possible to forward a client/visitor ip address to another site via redirect or curl. For example lets say when a visitor comes to my site I want to do a redirect and send them to site1.com. But instead of requesting that website using my ip address, I want to forward their ip address and use their very own ip address. Or for instance lets say I want to do a curl request, but instead of using my server's ip address, I want to forward their ip address and use their's. Is this possible? Or can anyone point me in the right direction?? Thanks

1) A Visitor Visits My Site
2) Visitor IP Address Gets Forwarded And Visitor Gets Redirected To Another 
         Site 
3) The Requesting Webpage See's Visitor IP Address Instead Of Mines
         Due to Forwarding

You cannot use someone else's IP address when making HTTP requests (say, via CURL or sockets) because it's your server that is doing the request, and IP addresses are detected by the remote server (you have no control over them).

However, you can send a header that defines the user's IP address and that you're making the request on their behalf. X-Forwarded-For is commonly used for that. It is up to the remote server to honor this header.

CURL example:

curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-Forwarded-For: " . $_SERVER['REMOTE_ADDR']
]);

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