2014-12-08 73 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