我做了一个脚本,通过API登录Vbulletin。
这是代码
<?php
include 'connector.class.php';
if ($connector==null)
{
$connector = new vbConnector();
}
$do=$_GET['do'];
if ($do=="login")
{
$user_name=$_GET['username'];
$user_pass=$_GET['password'];
$res= $connector->doLogin($user_name,$user_pass, 1);
echo $res;
}
当我通过网址请求这个时,例如(http://example.com?do=login&username=test&password=test),它工作得很好,一切都很好
当我尝试卷曲或file_get_content相同的 url 时,它永远不会记录我
这是我的一些试验
<?php
$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."'r'n"));
$context = stream_context_create($opts);
echo file_get_contents("http://192.168.5.55/vb_api/index.php?do=login&username=test&password=test");
您没有在file_get_contents调用中传递$context
。试试这个:
<?php
$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."'r'n"));
$context = stream_context_create($opts);
echo file_get_contents("http://192.168.5.55/vb_api/index.php?do=login&username=test&password=test",false,$context);
?>
我知道这很旧,但我刚刚找到了我的帖子的相关链接,希望能解决您的问题。