Php 在文本验证后监视网页

Php 在文本验证后监视网页,php,authentication,curl,automation,do-while,Php,Authentication,Curl,Automation,Do While,这是交易。我有一个要求,以监测某些密码保护的网页的变化,并播放声音报警时,页面的大小不同于我所知道的(即它被修改)。 这是我想出的一段代码 <?php $e = curl_init(); curl_setopt($e, CURLOPT_URL, 'http://example.com/Account/LogOn'); curl_setopt($e, CURLOPT_POST, 1); curl_setopt($e, CURLOPT_POSTFIELDS, 'UserName=xxx@ex

这是交易。我有一个要求,以监测某些密码保护的网页的变化,并播放声音报警时,页面的大小不同于我所知道的(即它被修改)。 这是我想出的一段代码

<?php

$e = curl_init();
curl_setopt($e, CURLOPT_URL, 'http://example.com/Account/LogOn');
curl_setopt($e, CURLOPT_POST, 1);
curl_setopt($e, CURLOPT_POSTFIELDS, 'UserName=xxx@example.com&Password=password');
curl_setopt($e, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($e, CURLOPT_REFERER, 'http://example.com');
curl_setopt($e, CURLOPT_RETURNTRANSFER, 1);
curl_exec($e);

$sizevalue = 2399;

do {
     curl_setopt($e, CURLOPT_URL, 'http://example.com/panel.php');
     $content = curl_exec($e);
     $numberofchars = strlen($content);
     sleep(15);
} while ($numberofchars = $sizevalue);

curl_close($e); 
echo '
      <audio controls="controls" autoplay="autoplay">
          <source src="/path/to/your/audio.mp3" type="audio/mp3">
          <source src="/path/to/your/audio.ogg" type="audio/ogg">
          <embed src="/path/to/your/audio.mp3">
      </audio>';
php?>

问题1。如果我错了,请纠正我,但据我所知,不是连接服务器,只发布一次用户名和密码,让连接保持活动状态,并使用
cookie.txt
中的身份验证密钥,在以后的操作中,它会在周期的每一个周期不断地将用户名和密码发送到登录表单。我该如何解决这个问题

问题2。我需要脚本给我一些临时状态,因为在那个时刻,如果不满足某些条件,它基本上会变成无限循环,托管脚本的服务器会给我超时错误


问题3。实现声音报警的最简单方法是什么?OGG文件回放?Youtube重定向?

问题1
curl\u multi\u exec
在您的情况下实际上不需要。保持卷曲手柄打开就足够了

问题2
sleep()
usleep()
在这方面效果很好

问题3:您可以只输出html标记。另一个选择是嵌入一个自动播放警报声的flash文件或视频。取决于运行的位置和目的

注意,像这样的脚本最好不要在浏览器中运行。最好设置一个cron脚本,以设置的间隔检查URL,并且不使用
do while
循环或
sleep

下面是用这些更正和一些示例编写的代码

<?php
set_time_limit(0); // this script will now run forever. but a safer value might be something like X hours or X number of minutes. 
$e = curl_init();
curl_setopt($e, CURLOPT_URL, 'http://example.com/Account/LogOn');
curl_setopt($e, CURLOPT_POST, true);
curl_setopt($e, CURLOPT_POSTFIELDS, 'UserName=xxx@example.com&Password=password');
// you'll need both CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE if you plan on NOT using curl's internal cookie handling
curl_setopt($e, CURLOPT_COOKIEJAR, 'cookie.txt'); // this is where we write the cookie data
curl_setopt($e, CURLOPT_COOKIEFILE, 'cookie.txt'); // this is where we read the cookie data to use
curl_setopt($e, CURLOPT_REFERER, 'http://example.com/');
curl_setopt($e, CURLOPT_RETURNTRANSFER, true);
// you can omit the next two lines if you think they won't be needed
curl_setopt($e, CURLOPT_FOLLOWLOCATION, true); // in case the remote server does some kind of http redirection, like a 301 redirect
curl_setopt($e, CURLOPT_MAXREDIRS, 3); // The maximum amount of HTTP redirections to follow, in case the remote server is badly configured and has an endless redirection loop
curl_exec($e);

$sizevalue = 2399;
$maximum_checks = 30; // I've added this as a cap for the loop, so that you only run it this many times.
$checks = 0;
$seconds = 15;

do {
     $checks++;
     curl_setopt($e, CURLOPT_URL, 'http://example.com/panel.php');
     $content = curl_exec($e);

     $numberofchars = strlen($content);

     // optionally... instead of the strlen method above you could also use 
     // http://php.net/manual/en/function.curl-getinfo.php
     if (!curl_errno($e)) {
        $info = curl_getinfo($e);
        echo 'content-length of download, read from Content-Length: field :' . $info['download_content_length']."<br>\n";
        $numberofchars = $info['download_content_length'];
     }
     if ($checks === $maximum_checks) {
        exit('No changes after '.($seconds * $maximum_checks).' seconds<br>'.PHP_EOL);
     }
     sleep($seconds); // wait for 15 seconds

} while ($numberofchars != $sizevalue); // fix up your TRUTH expression, don't forget it is != for proper comparison in your case. Without it you go into an infinite loop.

curl_close($e); 

// if our php script got this far then 
echo '
<audio controls="controls" autoplay="autoplay">
  <source src="/path/to/your/audio.mp3" type="audio/mp3">
  <source src="/path/to/your/audio.ogg" type="audio/ogg">
  <embed src="/path/to/your/audio.mp3">
</audio>';


?>

哇,贡献很大。但这里有两件事:1。警告:curl_setopt()[function.curl setopt]:如果启用了安全模式或在第13行的/home/a598399/public_html/mainest.php中设置了open_basedir,则无法激活curl_followllocation。其次,我认为服务器超时为60秒,我希望此脚本运行数小时。如何绕过此问题?CURLOPT_FOLLOWLOCATION已禁用,因为您的服务器php运行时启用了或。您可以禁用这些设置,但需要管理权限。如果您不知道这一点,请尝试要求您的网络主机公司进行更改。至于60秒的等待。你可以用。我已经更新了代码。
while($numberofchars!=$sizevalue)//无限循环正是我需要的。只要获取的站点没有更改,即大小相同,它就应该运行。当添加或删除某些内容时,音频应该开始播放。此外,超时问题不在于目标服务器,而在于我使用的网络主机,因此它会运行4次15秒的检查并超时。
错误324(net::ERR_EMPTY_RESPONSE):服务器关闭了连接,但没有发送任何数据。
我想我现在意识到,由于超时限制,我选择了错误的解决方案。虽然目标服务器允许无限时间的连接,但运行php脚本的主机并不能解决问题3。添加代码
echo'