Last active
October 12, 2015 03:28
-
-
Save tamcore/3963952 to your computer and use it in GitHub Desktop.
rewritten sav_get_file() function for the Savrix Android Market Wordpress Plugin to use cURL if available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sav_get_file($package_name) { | |
global $sav_file; | |
$sav_file = false; | |
$ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0'; | |
$headers = array( | |
'Accept-language' => 'en-us,en;q=0.5', | |
); | |
$url = 'https://play.google.com/store/apps/details?id=' . $package_name; | |
if (in_array('curl', get_loaded_extensions()) == true) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_USERAGENT, $ua); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$sav_file = curl_exec($ch); | |
curl_close($ch); | |
} else { | |
$opts = array( | |
'http' => array( | |
'method' => 'GET', | |
'header' => "User-Agent: ".$ua."\r\n" . | |
"Accept-language: en-us,en;q=0.5\r\n" . | |
"Connection: close\r\n" | |
) | |
); | |
$sav_context = stream_context_create($opts); | |
$sav_file = @file_get_contents($url, false, $sav_context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment