Last active
August 29, 2015 14:10
-
-
Save xemoe/1b84c2c8340eecf35d00 to your computer and use it in GitHub Desktop.
Curl
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
class Curl | |
{ | |
public function download($url, $header = null, $cookie = null, $post = null, $proxy = null) { | |
$agent = self::generate_useragent(); | |
$tor_address = '127.0.0.1:9050'; | |
$timeout = 300; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, $header); | |
curl_setopt($ch, CURLOPT_NOBODY, $header); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_COOKIE, $cookie); | |
curl_setopt($ch, CURLOPT_USERAGENT, $agent); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); | |
if($proxy !== false) | |
{ | |
$proxy = '210.14.152.91:8080'; | |
curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
} | |
if ($post) { | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
} | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} | |
private static function generate_useragent() { | |
$ua = array('Mozilla', 'Opera', 'Microsoft Internet Explorer', 'ia_archiver'); | |
$op = array('Windows', 'Windows XP', 'Linux', 'Windows NT', 'Windows 2000', 'Windows 7', 'OSX'); | |
return $ua[rand(0, 3)] . '/' . rand(1, 8) . '.' . rand(0, 9) | |
. ' (' . $op[rand(0, 6)] . ' ' . rand(1, 7) . '.' . rand(0, 9) . '; en-US;)'; | |
} | |
} | |
function startpage($page) | |
{ | |
$curl = new Curl; | |
$url = 'https://s5-us4.startpage.com/do/search'; | |
$post = [ | |
'cmd' => 'process_search', | |
'language' => 'english_uk', | |
'qid' => 'MJLOLSKMNMPK', | |
'rcount' => 1, | |
'rl' => NULL, | |
'abp' => 1, | |
'query' => 'agile', | |
'cat' => 'web', | |
'engine0 ' => 'v1all', | |
'startat' => ($page -1) * 10, | |
]; | |
$post = http_build_query($post); | |
return $curl->download($url, null, null, $post, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment