gpt4 book ai didi

php - 监控文本身份验证背后的网页

转载 作者:可可西里 更新时间:2023-11-01 13:30:48 25 4
gpt4 key购买 nike

这是交易。我需要监视某些受密码保护的网页的更改,并在页面大小与我所知道的不同(即它被修改)时播放声音警报。这是我想出的代码块。

<?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 中的身份验证 key 进行后续操作它不断发送每次循环的登录表单的用户名和密码。我该如何解决这个问题?

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

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

最佳答案

问题 1:curl_multi_exec 在您的情况下并不是必需的。保持 curl handle 打开就足够了。

问题 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>';


?>

关于php - 监控文本身份验证背后的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13824794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com