使用cURL通过PHP自动登录osCommerce

时间:2012-02-13 13:09:42

标签: php curl oscommerce

我正在开发一个应用程序,允许客户登录osCommerce网站来检索数据。到目前为止,我有这个脚本,适用于少数其他网站,如Wordpress,但不适用于osCommerce。

<?php
$ch = curl_init();
// Login here
curl_setopt($ch, CURLOPT_URL, 'http://demo.oscommerce.com/login.php');
curl_setopt ($ch, CURLOPT_POST, 1);
// Login/password
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'email_address=me@mail.xx&password=123456');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
// Get this file
curl_setopt($ch, CURLOPT_URL, 'http://demo.oscommerce.com/account.php');
$content = curl_exec ($ch);
curl_close ($ch); 
// Show the file
echo $content;
?>

我不知道问题出在哪里,因为我没有足够的PHP经验来看待它。 我应该修改什么才能使此脚本登录到网站?提前谢谢!

2 个答案:

答案 0 :(得分:0)

oscommerce只要我知道就会使用“用户名”而不是“email_address” - 除非您更改FORM字段的名称。尝试传递usename而不是email_address。

答案 1 :(得分:0)

您必须将curl发送到http://demo.oscommerce.com/login.php ?action = process 而不是http://demo.oscommerce.com/login.php才能直接检查变量