Problem to use user IP instead of server in CURL

-2

I'm using a CURL function in this way, to read the contents of curl with the user's IP, not the server's:

function curl($url) {
$curl = curl_init($url) or die("Erro, o CURL não está habilitado.");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Forwarded-For: ' . $_SERVER["HTTP_CF_CONNECTING_IP"]));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$string = curl_exec($curl);
curl_close($curl);
return $string;
}

However, it is not working. It ends up using the IP of the server even using $_SERVER["HTTP_CF_CONNECTING_IP"] , since the site is in Cloudflare.

Is it possible to fix this?

    
asked by anonymous 09.12.2018 / 14:39

1 answer

0

There's no way to fix it. Considering that cURL runs on the server, so the request will have the IP of the server.

What you're basically wanting is to forge an IP using TCP.

There is no way you can use the client's IP. Setting the X-Forwarded-For , X-Forwarded-IP or X-Real-IP (...) will not change anything, this is just any header. This header MUST be ignored by the site, no site should believe that your IP is one of these. You will only be able to "forge the IP" if your target believes in these headers, which is a mistake of it, only.

Forging an IP (using TCP) is extremely complicated, impossible in general cases due to the handshake. CURL, by itself, offers nothing that can help you with that.

    
13.12.2018 / 04:36