0

我有一个关于 curl 的问题,我到处搜索并尝试了很多东西,但我无法登录。我尝试登录到一个页面。我认为它与隐藏字段有关,隐藏字段不是随机生成的。

我熟悉php的基础知识,但不是专家。如果你对这个问题发表评论,你可以写一些评论吗,我真的很想学习!

这是我的代码:

<?php
$url = 'see url above';
$username = 'username';
$password = 'password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

echo '<pre>',print_r($info),'</pre>';

?>
4

2 回答 2

0

您应该通过查看返回的 cookie 来验证您是否已登录。无论您是否输入虚假信息,该应用程序似乎总是返回 HTTP 代码 200。

于 2013-04-04T21:05:35.923 回答
0

实际上,您不需要基本身份验证。
正如我所看到的,页面中有简单的表单和隐藏的变量。尝试通过 POST 发送它们。

像这样的东西:

$url =  'http://www.cibap.nl/index.php';
$username = 'username';
$password = 'password';

$post_data = array(
'ACT'       => '9',
'RET'       => '/login',
'site_id'   => '1',
'username'  => $username,
'password'  => $password,
'autologin' => '1'  
);

$ch = curl_init($url);

$postargs = http_build_query($post_data);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);

//Use cookie file if needed (probably needed)
//$cookiefile = '/path/to/cookie.txt'; 
//any filename, curl stores and reads this file next time
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); 

//curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$output = curl_exec($ch);   
curl_close($ch);

echo '<pre>',print_r($output),'</pre>';
于 2013-04-05T19:11:14.753 回答