0

I am using the Official PHP client library for IPinfo and willing to find IP Geolocation and carrier-related data. I have downloaded its PHP Library and it is working fine from a local server which is on a direct Internet connection. Whereas, when I am trying to use it from a server inside my organization, which is having a Proxy Server forwarding port 80 requests only (Proxy Server: 10.2.1.5:3128), the request is not going through.

Usually, I achieve this through procedural PHP by:

$api_url = 'https://some.url';
$curl = curl_init($api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PROXY, 'http://10.2.1.5:3128');     // Adding here
$curl_response = curl_exec($curl);
curl_close($curl);

Now, in the IPinfo library, it has different sytaxt to use:

use ipinfo\ipinfo\IPinfo;
$access_token = '<my token>';
$client = new IPinfo($access_token);
$ip_address = '76.77.78.79';
$details = $client->getDetails($ip_address);
$get_region = $details->region;
...

But here, I cannot add my curl_setopt - the proxy. I have seen its IPinfo.php file as well code but nowhere find where to add the proxy details. Where and how should I add it? Please suggest.

  • As per the the library [source](https://github.com/ipinfo/php/blob/master/src/IPinfo.php#L30) and its [Composer configuration](https://github.com/ipinfo/php/blob/master/src/IPinfo.php#L30) it's using [Guzzle](https://packagist.org/packages/guzzlehttp/guzzle#6.3.3) to handle network transfers. You can probably create a custom class that extends `IPinfo` and inject one of [techniques to set a proxy](https://stackoverflow.com/questions/32324893/set-proxy-in-guzzle). – Álvaro González Mar 28 '20 at 15:44
  • OK @ÁlvaroGonzález I’ll check. – Kaushal Shakya Mar 28 '20 at 22:55
  • @ÁlvaroGonzález can't figure out where to put the proxy info. Should I put it like this? $client = new IPinfo('proxy' => 'tcp://12.34.56.78:3128',$access_token); – Kaushal Shakya Mar 29 '20 at 11:19
  • or like this: $details = $client->getDetails('GET', '/', ['proxy' => 'tcp://10.2.5.1:3128'],$ip_address); – Kaushal Shakya Mar 29 '20 at 11:21
  • The library does not support proxy. That's why I say you need to extend it and code your own solution. Please note that, despite being downloaded with Composer, it's still regular PHP code. You can open it in your IDE and see how it works. – Álvaro González Mar 29 '20 at 11:29
  • Already tried it, but it is breaking the code. – Kaushal Shakya Mar 29 '20 at 12:05
  • @ÁlvaroGonzález awaiting your reply. Can you guide me how to create a custom class that extends IPinfo. – Kaushal Shakya Apr 04 '20 at 02:46

0 Answers0