If you have ever wanted to be able to login your customers from an external domain you can do so in two obvious ways:
However if you want to be able to log the customer in without them filling out a form then perhaps the following method is good for you?
Firstly we need to have the correct username+password for our customer – as long as you have this it shouldn’t be a problem.
On our external domain we can create a new file – something like crossdomainlogin.php.
In this php file paste in the following:
session_start();$string = "login[username]=".urlencode("me@mymagentodomain.co.uk")."&login[password]=".urlencode("password");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://www.mymagentodomain.co.uk/customer/account/loginPost');curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id());curl_setopt($ch, CURLOPT_COOKIESESSION, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $string);curl_setopt($ch, CURLOPT_HEADER, true);$output = (string) curl_exec($ch);curl_close($ch);preg_match('/frontend=(.+); expires=/i', $output, $matches);$temp = $matches[0];$sid = str_replace(array("frontend=","; expires="), "", $temp);//echo $sid;header('Location: http://www.mymagentodomain.co.uk/customer/account/?SID='.$sid);What the above code does is:
Log’s you in via CurlStores the new session IDTransfers you to the Magento site with the new session ID stamped to your URLI hope you have enjoyed this blog and find it useful – thanks for visiting the Magento Blog here at e-commerce web design, home of the Magento Fox!
Robert Kent Author Page
Không có nhận xét nào:
Đăng nhận xét