【发布时间】:2010-11-16 02:08:41
【问题描述】:
我将如何编写一个可以登录并接收服务器发送的所有 cookie 的简单 PHP 机器人? ...然后在需要时将它们寄回?
任何建议将不胜感激。
【问题讨论】:
我将如何编写一个可以登录并接收服务器发送的所有 cookie 的简单 PHP 机器人? ...然后在需要时将它们寄回?
任何建议将不胜感激。
【问题讨论】:
首先,您的问题过于宽泛且缺乏细节,无法真正有效地回答。就是说,我会试一试。
不知道您所说的“登录”到底是什么意思,我假设您希望脚本能够通过 HTTP 请求将一些数据发布到另一个脚本。 CURL Library 对此有好处。它能够发布数据和处理cookies。
编辑:得到了 Zed 的忍者。 ;)
【讨论】:
如果由于某种原因您无法在服务器上使用curl 扩展(未安装扩展),您可以使用诸如Snoopy 之类的类,它仍然允许您使用curl 二进制文件或使用套接字检索信息。
史努比处理 cookie。
至于编写机器人本身,这只是发送正确请求的问题。这是史努比的一个例子:
$snoopy = new Snoopy;
// The following needs to reflect the form configuration of the site
$login = array('usr' => 'hi', 'pwd' => 'hello');
if($snoopy->submit('http://example.com/login', $login) === false) {
// output the response code
die($snoopy->response_code . ':' . $snoopy->error);
}
//Request succeeded (doesn't mean we are logged in)
// output the results
echo $snoopy->results;
// Check the results to see if you are logged in and
// Continue using $snoopy.
// It will pass the proper cookies for the next requests.
【讨论】:
借助cURL 库?
【讨论】: