我正在尝试通过cURL和PHP登录oscommerce管理面板,我已经在post_array中输入了正确的登录名和密码,但我不断收到“错误:管理员登录尝试无效”。我发送POST数据并正确保存cookie吗? 这是我的代码:
<?php
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0E)';
$username = 'PromptUsername';
$password = 'PromptPassword';
$URL = 'http://www.example.com/admin/login.php'; //'http://www.example.com/admin/categories.php?cPath=21';
$path1 = 'cookies/';
$post_array = array(
'username'=>'usernAme',
'password'=>'passw0rd'
);
$authURL = $URL.'?action=process';
// Login here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $authURL);
curl_setopt($ch,CURLOPT_USERAGENT,$agent);
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path1.'cookies.txt') );
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($path1.'cookies.txt'));
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_REFERER, $URL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_array));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'method' => 'POST',
"Authorization: Basic ".base64_encode("$username:$password")."\r\n",
));
$debug = curl_getinfo($ch, CURLINFO_HTTP_CODE);
var_dump($debug);
$store = curl_exec ($ch);
var_dump($store);
?>
答案 0 :(得分:0)
您正在使用授权标头添加\r\n
,这会扰乱服务器。只需删除它们。
"Authorization: Basic ".base64_encode("$username:$password"),