zoukankan      html  css  js  c++  java
  • PHP 访问链接的3种方式

     对于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;
    }
  • 相关阅读:
    【坑】提答题
    Google Code Jam 2014 Round2
    湖北省队互测Week1
    [xyz模拟题]动态维护树的直径
    音乐会的等待【单调栈】
    51nod1202【DP-树状数组维护】
    51nod1113【矩阵快速幂】
    51nod1255【贪心-栈的应用】
    Lightoj1059【最小生成树】
    SPOJ IAPCR2F 【并查集】
  • 原文地址:https://www.cnblogs.com/xs-yqz/p/7601048.html
Copyright © 2011-2022 走看看