Custom IP in CURL [closed]
This doesnt work. Please help!
curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
The REMOTE_ADDR
is not user-provided, it's taken from the TCP connection. There's no such thing as a "custom IP".
You can't do it, because the IP address comes from the TCP/IP data packet. The only way to change IP address is using a proxy server
You can't send REMOTE_ADDR
as there is no such HTTP header. Even if you could, the response would be received by the specified host (REMOTE_ADDR
) and not you. What you are trying to do is called IP Spoofing. You can read more here.
If you don't actually have that IP, don't bother trying as others have said. If however you have that IP on your server, and just want to choose which one of your ips to use on an external connections, you can use curl_setopt(CURLOPT_INTERFACE,'xxx.xxx.xxx.xxx');
(the second argument can be an interface name, an IP address or a host name).
精彩评论