This is CURL Ready function , to use it just call do post if the page you are calling has post variables , or get if it has get variables :)
CURL PHP Ready function !
$random=rand(1, 100000);
$cookie=$random . ".txt";
$agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
function doRequest($method, $url, $referer, $agent, $cookie, $vars) {
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($referer != "") {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
if (substr($url, 0, 5) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
}
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
return $data;
} else {
return curl_error($ch);
}
}
function get($url, $referer, $agent, $cookie) {
return doRequest('GET', $url, $referer, $agent, $cookie, 'NULL');
}
function post($url, $referer, $agent, $cookie, $vars) {
return doRequest('POST', $url, $referer, $agent, $cookie, $vars);
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.