2014-12-08 47 views
0

我用这个洛一起Magento的卷曲持久登录卷曲的Magento和获取数据

session_start(); 

$string = "login[username]=".urlencode("[email protected]")."&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)我想知道如何保持记录,卷曲

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

3)Thx提前!

回答

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

+0

它不是为Magento的 – user2327112 2014-12-08 11:49:01

+0

你是什么意思? – Radu 2014-12-08 12:18:04

+0

只是我尝试连接到一个magento网站,并在帐户页面中获取一些信息。 – user2327112 2014-12-10 17:23:17