对采用curl模拟登录做了一下简单的测试,curl模拟登录代码如下,貌似参数的提交可以用字串的形式也可以用数组的形式?
<?php
$ch = curl_init();
/*$vars = array(
'formhash' => '2d47d0be',
'referer' => 'index.php',
'username' => 'username',
'password' => 'password'
);
*/
$vars = 'ation=log&username=username&password=password';
curl_setopt($ch, CURLOPT_URL, "http://localhost/phpstudy/curl/post.php");//这是要提交的网页
curl_setopt($ch, CURLOPT_REFERER, "http://localhost");//这个是假冒的url
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);//顺便测试了下post提交数据
ob_start();
curl_exec($ch);
$response = ob_get_contents();
ob_end_clean();
print_r($response);
if(curl_errno($ch))
{
print curl_error($ch);
}
curl_close($ch);
?>