dongzi3434 2013-09-28 18:26
浏览 47
已采纳

cURL从另一页显示

Im running PHP 5.4.

This is my setup:

../checker.php

../index.php

from conscript.php I use a cronjob to run it each 5 minutes or so but I want the echo of the cURL to display on index.php. How do I receive the echo at index.php?

It would also be possible to let cURL store the results from the checker.php in a file for ehm. results.php and let index.php grab/iframe from results.php but I have no idea how.

  • 写回答

1条回答 默认 最新

  • douyu0852 2013-09-28 20:08
    关注

    cronCheckUrls.php

    <?
    //Set name of text file
    $file = "urlUpResults.txt";
    
    //Create blank file/delete contents of existing file before run rest of script
    file_put_contents($file, " ");
    
    //Build array of sites to check
    $sitesArray = array("http://www.minecraft.net", "http://www.4stats.tk", "http://www.google.com", "http://www.stackoverflow.com", "http://www.brokentestwebsite.com");
    
    
    foreach ($sitesArray as $value) { 
    if (TPBUC($value))
        $upStatus = "<p>" . $value . " is up.</p>";
     else
        $upStatus = "<p>" . $value . " is down.</p>";
        file_put_contents($file, $upStatus, FILE_APPEND);
    }
    
    
    //cURL function
    
            function TPBUC($url){
                 $agent = "Mozilla/5.0 (compatible; TPBUC/1.0;)";$ch=curl_init();
                 curl_setopt ($ch, CURLOPT_URL,$url );
                 curl_setopt($ch, CURLOPT_USERAGENT, $agent);
                 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt ($ch,CURLOPT_VERBOSE,false);
                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
                 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
                 curl_setopt($ch,CURLOPT_SSLVERSION,3);
                 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
                 $page=curl_exec($ch);
                 $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                 curl_close($ch);
                 if($httpcode>=200 && $httpcode<400) return true;
                 else return false;
          }
    
    ?>
    

    index.php

    <?
    $file = "urlUpResults.txt";
    echo "<h1>UpCheck results:<h1><br>" . file_get_contents($file);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网