我在使用 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>
<button type="reset" class="btn">Cancel</button>
</div>
</fieldset>
</form>
有任何想法吗?我做错了什么?我尝试更改代码,使用示例代码。依然没有。