I need to send a request with user IP address and not server IP address. I found similar question here (cURL ip address), but it didn't help me. Any ideas what is wrong here? I did a print of $ip and it shows correct user IP there, so it should be okay, but it's not.
$curl = curl_init("MYURL");
curl_setopt( $curl, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
curl_exec($curl);
I don't think you can do this at all. First of all, you're trying to use another one's IP to make a request, which is basically not possible unless you're using a proxy. Secondly, if you've read the answer in the link you've provided thoroughly, what you're trying to do here is tricking the server in thinking you're another user by faking the IP in the header. This will work if the (target) server script that handles the response, only checks HTTP headers (which seems pretty insecure to me).
I'll try to explain it with an example. Let's say you have your user's IP which is 12.34.56.78
and your own IP is 99.88.77.66
. Then if you send a request with the header HTTP_X_FORWARDED_FOR: 12.34.56.78
from your own server/pc (99.88.77.66
) and the server ignores that and/or also checks $_SERVER['REMOTE_ADDR]
(which contains 99.88.77.66
), it will notice that it's not the user's IP who's accessing the URL, but yours.