I am using file_get_content() to open a file from external url. But when i do so, the url request ip is being set as the server ip instead of the client ip. is there any way to solve this?
I found this by testing the following code.
<?php
$ip = $_SERVER['REMOTE_ADDR'];
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"HTTP_CLIENT_IP: $ip" .
"remote_addr: $ip".
"server_addr: $ip".
"Cookie: foo=bar\r\n",
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://ifconfig.me/ip', false, $context);
var_dump($file);
Output : string(10) "153.92.0.6" (It is my domain ip) Output i wanted is client ip instead of domain ip