简体   繁体   English

无法卷曲登录

[英]Can't login with curl

I've got a question about curl, i've searched everywhere en tried many things, but i can't login. 我有一个关于卷曲的问题,我到处搜索过很多东西,但是我无法登录。 I try to login to a page. 我尝试登录页面。 I think it has something to do with the hidden fields, the hidden fields are not random generated. 我认为这与隐藏字段有关,隐藏字段不是随机生成的。

I'm familiar with the basics of php, but not a expert. 我熟悉php的基础知识,但不是专家。 If you comment on this question could you maybe write some comments with it, i really want te learn! 如果您对此问题发表评论,也许您可​​以写一些评论,我真的很想学习!

Here is my code: 这是我的代码:

<?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>';

?>

You should verify that you are logged in by looking at the cookies that are returned. 您应该通过查看返回的cookie来验证您是否已登录。 The application appears to always return HTTP code 200 whether you put in bogus information or not. 无论您是否输入虚假信息,该应用程序似乎总是返回HTTP代码200。

Actually you do not need basic auth. 实际上,您不需要基本身份验证。
As I can see there are simple form and hidden vars in the page. 如我所见,页面中有简单的表单和隐藏的var。 Try to send them via POST. 尝试通过POST发送。

Something like this: 像这样:

$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>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM