/*
* Author: HBK
* Released: August 16, 2010
* Description: An example of the getWithCurl() function in order to grab contents from a website while.
*/
$url = 'http://www.google.com';
function getWithCurl($url)
{
$curl = curl_init();
// Setup headers - I used the same headers from Firefox version 2.0.0.6
// below was split up because php.net said the line was too long. :/
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
// browsers keep this blank.
$referers = array("google.com", "yahoo.com", "msn.com", "ask.com", "live.com");
$choice = array_rand($referers);
$referer = "http://" . $referers[$choice] . "";
$browsers = array("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20060918 Firefox/2.0", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)");
$choice2 = array_rand($browsers);
$browser = $browsers[$choice2];
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $browser);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, $referer);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_MAXREDIRS, 7);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($curl);
if ($data === false) {
$data = curl_error($curl);
}
// execute the curl command
curl_close($curl);
// close the connection
return $data;
// and finally, return $html
}
// uses the function and displays the text off the website
$text = getWithCurl($url);
echo $text;
?>
About Me
- Hardik Patel
- Hi…My Self Hardik Patel. The meaning of my name is “From the Bottom of the Heart” , “Hearty boy”. I am working as Sr. Web Application Developer at IndiaNic Infotech Ltd. in Ahmedabad, Gujarat, India. I have total 2.5 Years of Experience as PHP-Open source Professional. Well , I have done Master of Computer Application & Information Technology (M.sc [ IT ]) from K.S.School of Business management at Gujarat University in 2009. I have always believed in simple living and high thinking. I am a confident, commited and ambitious person. I am also a creative and hard working person but at times somewhat lazy too. But when I determine something I do it till it gets finished. I am very funny in nature and mixed with everyone very fast. Well I am very talkative person but people likes my company …….I love every food which is Tasty. I like travelling , like to play Chess and Cricket and surf on the net. And if you know more about me than defiantly you have to meet me earlier. Thanks
No comments:
Post a Comment