如何使用PHP连接到SOCKS5或HTTP

时间:2019-10-08 17:59:55

标签: php instagram-api

我有一个连接到Instagram的PHP代码;我正在尝试将代码设置为使用特定的SOCKS5或HTTPS服务器。但是我似乎语法不正确。

我尝试使用curl_setopt($ch, CURLOPT_INTERFACE, "51.79.24.111:8080");,但仍然无法正常工作。我不知道这是怎么回事。

function request($ighost, $useragent, $url, $cookie = 0, $data = 0, $httpheader = array(), 
  $proxy = 0, $userpwd = 0, $is_socks5 = 0)
{
      $url = $ighost ? 'https://i.instagram.com/api/v1/' . $url : $url;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);


if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, '51.79.24.111:8080');
}

if ($userpwd) {
 curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'username:password');
}

if ($is_socks5) {
  //  curl_setopt($ch, CURLOPT_PROXYTYPE, 'socks5://username:password@51.79.24.111:8080');
}

if ($httpheader) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
}

curl_setopt($ch, CURLOPT_HEADER, 1);
if ($cookie) {
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}

if ($data):
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
endif;
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch);
if (!$httpcode) {
    return false;
} else {
    $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
    $body = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
    curl_close($ch);
    return array($header, $body);
}

}

0 个答案:

没有答案