Jawad Malik
Jawad Malik

Reputation: 73

cURL Requests through client or user IP

create a file index.php with this code and request this page client.php which purpose to show the ip address of user who will access the page. Whenever somone request through index.php its shows the server ip or when someone access client.php directly it will shows user or client ip. is this possible to make request through user ip ?

$url = 'http://www.bomberfeeds.com/demo/client.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

Upvotes: 1

Views: 2726

Answers (1)

René Höhle
René Höhle

Reputation: 27285

You can set a custom header for example X-Forwarded-For and set the user IP to that header. You can use that header on the other site and work with them. Some loadbalancers do exactly the same and use a custom header for the user ip.

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Forwarded-For: ' . $externalIpAdress,
));

Upvotes: 2

Related Questions