持久登录curl magento并获取数据

时间:2014-12-08 07:53:16

标签: php magento curl

我使用这个来登录与卷曲的magento

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);

1)我想知道如何使用curl记录会话

2)如何从记录会话的其他页面获取数据。

3)Thx提前!

1 个答案:

答案 0 :(得分:0)

试试这个:

session_start(); 
$cookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'];

session_write_close(); 

$ch = curl_init('url_here');
...
...
...
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
...
... 
curl_exec($ch); 
curl_close($ch); 

http://php.net/session_write_close