0

I'm trying to get a response.

Using curl_exec works fine, but the problem is that it gets a response with different IP.

I want to get response from client or user IP, rather than server IP.

$URL = "https://drive.google.com/get_video_info?docid=".$_SERVER["QUERY_STRING"];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 2);
$response_data = urldecode(urldecode(curl_exec($curl)));
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123

2 Answers2

1

The curl runs on the server and not in the client. Any HTTP command issued by curl will use the server IP as the requester.

  • Depending on the service you are invoking, probably you can use the X-Forwarded-For HTTP header used in the Internet Proxies.

    $URL = "https://drive.google.com/get_video_info?docid=".$_SERVER["QUERY_STRING"];
    $curl = curl_init();
    
    // set the command as requested by the client IP
    curl_setopt($curl,CURLOPT_HTTPHEADER,array('X-Forwarded-For: '. $_SERVER['REMOTE_ADDR']));      
    
    curl_setopt($curl, CURLOPT_URL, $URL);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 2);
    $response_data = urldecode(urldecode(curl_exec($curl)));
    

The service you are invoking may use the header to determine the ip of the originator. Using the X-Forwarded-For will not work with all the services and server-side frameworks.

  • If you want to make a request from the client, probably you need to use javascript (e.g. by using XMLHttpRequest or some functions in JQuery or Angular) to make the request.

You may check:

Jaime
  • 5,435
  • 2
  • 18
  • 21
  • thankyou for your answer exactly you understand my problem but unfortunately this solution not work for me :( – Jawad Malik Aug 15 '17 at 16:48
  • There are other forwarding headers in addition to `X-Forwarded-For`- You may check https://stackoverflow.com/questions/13111080/what-is-a-full-specification-of-x-forwarded-proto-http-header -- If the API you are using does not recognize that (or other) forwarding headers, you must use javascript to create a connection from the browser itself. – Jaime Aug 15 '17 at 17:25
0

get the client to install curl on its own computer, and run the code there, or get the client to install a proxy on its computer, then proxy your connection through the client's with CURLOPT_PROXY & co.

hanshenrik
  • 19,904
  • 4
  • 43
  • 89