Created
September 9, 2014 19:22
-
-
Save khoand0000/425f174a26ae2be440a7 to your computer and use it in GitHub Desktop.
Url class
This file contains hidden or 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 | |
/** | |
* Author: videde | |
* Date: 8/21/13 | |
* Time: 12:46 AM | |
*/ | |
require_once 'random-user-agent.php'; | |
class Url { | |
/* | |
* use proxy: | |
* $opt = array( | |
CURLOPT_PROXY => $proxy['ip'].":".$proxy['port'], | |
CURLOPT_PROXYPORT => $proxy['port'], | |
CURLOPT_PROXYUSERPWD => $proxy['username'].":".$proxy['password'] | |
); | |
*/ | |
public static function makeCurl($url, $randomUserAgent=false, $opt = null) | |
{ | |
$ch = curl_init(); | |
$arr = array(CURLOPT_URL => $url) + self::makeCurlOptions($randomUserAgent); | |
if ($opt != null) { | |
$arr = $arr + $opt; | |
} | |
curl_setopt_array($ch, $arr); | |
$ret = curl_exec($ch); | |
curl_close($ch); | |
return $ret; | |
} | |
public static function makeCurlOptions($randomUserAgent=false) | |
{ | |
$userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'; | |
if ($randomUserAgent) { | |
$userAgent = random_user_agent(); | |
} | |
return array( | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_TIMEOUT => 5, | |
CURLOPT_USERAGENT => $userAgent | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment