Skip to content

Commit

Permalink
Merge pull request #30 from aurmil/proxy
Browse files Browse the repository at this point in the history
Add possibility to set a proxy
  • Loading branch information
Bolandish committed Jan 10, 2017
2 parents 2f49795 + d2fc5d1 commit db95094
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Instagram.php
Expand Up @@ -2,6 +2,21 @@
namespace Bolandish;

class Instagram {
/**
* @var array
*/
protected static $curlProxy = array();

public static function setCurlProxy(array $config) {
foreach ($config as $k => $v) {
if ((in_array($k, array(CURLOPT_HTTPPROXYTUNNEL)) && is_bool($v))
|| (in_array($k, array(CURLOPT_PROXYAUTH, CURLOPT_PROXYPORT, CURLOPT_PROXYTYPE)) && is_int($v))
|| (in_array($k, array(CURLOPT_PROXY, CURLOPT_PROXYUSERPWD)) && is_string($v))
) {
self::$curlProxy[$k] = $v;
}
}
}

protected static function getContentsFromUrl($parameters) {
if (!function_exists('curl_init')) {
Expand All @@ -13,6 +28,9 @@ protected static function getContentsFromUrl($parameters) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'q='.$parameters);
foreach (self::$curlProxy as $k => $v) {
curl_setopt($ch, $k, $v);
}
$headers = array();
$headers[] = "Cookie: csrftoken=$random;";
$headers[] = "X-Csrftoken: $random";
Expand Down

0 comments on commit db95094

Please sign in to comment.