Skip to content

Commit

Permalink
add proxy support:
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Smeeckaert committed Jan 23, 2016
1 parent d8ab3c1 commit 1e90341
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sharrre.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
$json['url'] = $_GET['url'];
$url = urlencode($_GET['url']);
$type = urlencode($_GET['type']);

$proxy = null;
$proxyAuth = array();
if (filter_var($_GET['url'], FILTER_VALIDATE_URL)) {
if ($type == 'googlePlus') { //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
$contents = parse('https://plusone.google.com/u/0/_/+1/fastbutton?url='.$url.'&count=true');
$contents = parse('https://plusone.google.com/u/0/_/+1/fastbutton?url=' . $url . '&count=true');

preg_match('/window\.__SSR = {c: ([\d]+)/', $contents, $matches);

Expand All @@ -29,6 +30,8 @@

function parse($encUrl)
{
global $proxy;
global $proxyAuth;
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
Expand All @@ -43,7 +46,12 @@ function parse($encUrl)
CURLOPT_SSL_VERIFYPEER => false,
);
$ch = curl_init();

if ($proxy != null) {
$options[CURLOPT_PROXY] = $proxy;
if (isset($proxyAuth['user']) && isset($proxyAuth['pwd'])) {
$options[CURLOPT_PROXYUSERPWD] = $proxyAuth['user'] . ':' . $proxyAuth['pwd'];
}
}
$options[CURLOPT_URL] = $encUrl;
curl_setopt_array($ch, $options);

Expand Down

0 comments on commit 1e90341

Please sign in to comment.