我正在尝试使用curl进行magento登录,我需要的是与magento在同一台服务器上 我的代码目前无效:
$data = array(login[username]"=>"email", "login[password]"=>"password");
$url="https://example.com/customer/account/loginPost/";
$options=array();
$ch = curl_init();
$params = http_build_query($params);
$def_options = array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_FOLLOWLOCATION =>1,
CURLOPT_HEADER=>0,
CURLOPT_RETURNTRANSFER =>1,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR=> '/tmp/cookies.txt',
CURLOPT_COOKIEFILE=>'/tmp/cookies.txt',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST=> true,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_TIMEOUT => 100,
CURLOPT_VERBOSE=>TRUE,
CURLOPT_STDERR=>$verbose
);
$def_options += $options;
curl_setopt_array($ch,$def_options);
$response = trim(curl_exec($ch));
$info = curl_getinfo($ch);
curl_close($ch);
echo $response;
这只是重定向我在登录页面上没有任何错误或成功登录,它似乎不发送任何POST数据。
有什么建议吗?
答案 0 :(得分:0)
第一。你在第一行错过了一个引号:
$data = array("login[username]"=>"email", "login[password]"=>"password");
^
秒。将$params = http_build_query($params);
更改为$data = http_build_query($data);
你准备好了。