Created
February 28, 2013 12:56
-
-
Save danillab/5056537 to your computer and use it in GitHub Desktop.
post-m
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
<?php | |
function post($url, $postdata = 0){ | |
$ch = curl_init($url); | |
if(!empty ($GLOBALS['_proxy'])){ | |
curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['_proxy']); | |
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); | |
} | |
if(!empty ($postdata)){ | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); | |
} | |
curl_setopt($ch, CURLOPT_COOKIEJAR, "cook.tmp"); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, "cook.tmp"); | |
if(!empty ($GLOBALS['_useragent'])){ | |
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['_useragent']); | |
} else{ | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0'); | |
} | |
curl_setopt($ch, CURLOPT_REFERER, $url); | |
//curl_setopt ( $ch, CURLOPT_VERBOSE,2 ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 60); | |
$headers = array(); | |
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; | |
$headers[] = "Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3"; | |
$headers[] = "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7"; | |
$headers[] = "Keep-Alive: 115"; | |
$headers[] = "Connection: keep-alive"; | |
$headers[] = "Expect:"; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); | |
$result = curl_exec($ch); // run the whole process | |
curl_close($ch); | |
return $result; | |
} | |
function set_useragent(){ | |
$arr = array( | |
'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; 3301; MyIE2)', | |
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Maxthon; SV1; .NET CLR 2.0.40607)', | |
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; AIRF; .NET CLR 1.0.3705)', | |
'Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)', | |
'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.0; ru-RU)', | |
'Mozilla/5.0 (Windows; U; MSIE 7.1; Windows NT 6.0; en-US)', | |
'Mozilla/5.0 (Windows; U; MSIE 8.0; Windows NT 6.0; ru-RU)', | |
'Mozilla/5.0 (Windows; U; Windows NT 5.0; ru; rv:1.6) Gecko/20040113', | |
'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6', | |
'Mozilla/5.0 (Windows; U; Win98; ru-RU; rv:1.4) Gecko Netscape/7.1 (ax)', | |
'Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:0.9.2.1) Gecko/20010901', | |
'Mozilla/5.0 (X11; U; Linux; i686; ru-RU; rv:1.6) Gecko Galeon/1.3.14', | |
'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8', | |
'Opera/9.62 (X11; Linux x86_64; U; ru) Presto/2.1.1', | |
'Opera/8.01 (Windows NT 5.1; U; ru)', | |
'Opera/8.05 (Windows NT 5.1; U; en)', | |
'Opera/7.21 (Windows NT 5.2; U)', | |
'Opera/9.70 (Linux i686; U; ru) Presto/2.2.0'); | |
$GLOBALS['_useragent'] = $arr [array_rand($arr)]; | |
} | |
/** | |
* @param $RegEx | |
* @param $Text | |
* @param bool $isAll -1 Use match_all, 2 match_all PREG_SET_ORDER | |
* @param bool $n Return $m[N] | |
* @param bool $n1 $m[][N] | |
*/ | |
function m($regex, $text, $isall = false, $n = false, $n1 = false){ | |
$regex = addcslashes($regex, '#'); | |
if(false === $isall){ | |
if(!preg_match('#' . $regex . '#si', $text, $m)){ | |
return false; | |
} | |
if(!(false === $n)){ | |
return $m [$n]; | |
} else{ | |
return (isset ($m [1]) ? $m [1] : $m [0]); | |
} | |
} else{ | |
if(!preg_match_all('#' . $regex . '#si', $text, $m, (2 === $isall ? PREG_SET_ORDER : PREG_PATTERN_ORDER))){ | |
return false; | |
} | |
if(!(false === $n)){ | |
return $m [$n]; | |
} elseif(!(false === $n) and !(false === $n1)){ | |
return $m [$n] [$n1]; | |
} else{ | |
return $m; | |
} | |
} | |
} | |
function arand($arr){ | |
if(is_array($arr)){ | |
return $arr [mt_rand(0, count($arr) - 1)]; | |
} | |
} | |
function i($str){ return iconv('windows-1251', 'utf-8//IGNORE', $str); } | |
function i1($str){ return iconv('utf-8', 'windows-1251//IGNORE', $str); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment