Jawad Malik Jawad Malik -3 years ago 167
PHP Question

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);
echo $data;

Answer Source

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,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download