'Prestashop cUrl Login
I'm trying to log-in as customer using cUrl method in Prestashop.
When I send my cUrl request, my values are inserted in the log-in form but the form is not submitted.
Here my code:
$url = 'http://example.com/prestashop/login';
$fields = array(
'submitLogin' => 1,
'email' => '[email protected]',
'passwd' => '123456',
);
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
//print 'yes123';die;
$response = json_decode($result);
print_r($response);
curl_close($ch);
Solution 1:[1]
$url = 'http://example.com/prestashop/login';
$fields = array(
'submitLogin' => 1,
'email' => '[email protected]',
'passwd' => '123456',
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
echo json_encode($result);
Solution 2:[2]
Be carrefull with the first uppercase letter SubmitLogin.
I've just waste one day of work because of this!
Then, i decided to prevent other users make same error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | IAy |
Solution 2 | HeineFR |