對於php訪問url的方法比價多,對於一些防護比較低的網站,可以輕易的實現刷網站瀏覽量的可能
1.fopen方式
function access_url($url) { if ($url=='') return false; $fp = fopen($url, 'r') or exit('Open url faild!'); if($fp){ while(!feof($fp)) { $file.=fgets($fp).""; } fclose($fp); } return $file; }
2.file_get_contents方式(打開遠程文件的時候會造成CPU飆升。file_get_contents其實也可以post)
$content = file_get_contents("http://www.google.com");
3.curl方式
function curl_file_get_contents($durl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $durl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 獲取數據返回 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在啟用 CURLOPT_RETURNTRANSFER 時候將獲取數據返回 $r = curl_exec($ch); curl_close($ch); return $r; }
如果需要不斷訪問某個鏈接,只需寫一個for循環就好
for ($i=0; $i < 10 ; $i++) { //file_get_contents("http://www.speakphp.com/?post=98"); //access_url("http://www.speakphp.com/?post=98"); curl_file_get_contents("http://www.speakphp.com/?post=98"); echo $i; }