繁体   English   中英

PHP CURL登录问题

[英]PHP CURL Problems with login

我使用cURL登录时遇到问题。 这是我的代码:

<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', '1');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mysite.net/post/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/test.cookie'); // replace this with /tmp or something like that
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'accountName' => 'name',
    'accountPassword' => 'password'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

echo $output; 
?> 

我的代码有什么问题? 我无法登录。 对不起我的英语不好。

表单来自mysite.net

<form class="form-horizontal" method="post" action="post/login.php">
<input type="hidden" name="securitytoken" value="672385374d4ed88e5ac0d6aaf29ae5f25280ed549a01f1.65943444">
<fieldset>
<h2>Account Login</h2>
<div class="control-group">
<label class="control-label" for="accountName">Account name</label>
<div class="controls">
<input type="text" class="input-large" id="accountName" name="accountName">
</div>
</div>
<div class="control-group">
<label class="control-label" for="accountPassword">Account password</label>
<div class="controls">
<input type="password" class="input-large" id="accountPassword" name="accountPassword">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit</button>&nbsp;
<button type="reset" class="btn">Cancel</button>
</div>
</fieldset>
</form>

有任何想法吗? 我做错了什么? 我尝试更改代码,并使用示例代码。 依然没有。

有几个问题。

  1. 您需要提供securitytoken以及accountNameaccountPassword 为此,您需要抓取页面,提取令牌并使用凭证将其发布
  2. 正常情况下(通过浏览器)表单使用哪种enctype? 您可以通过任何浏览器流量插件进行查找。 如果提供$data作为数组,则cURL将使用multipart/form-data 如果是字符串-内容类型将为application/x-www-form-urlencoded

暂无
暂无

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

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