Php 永久登录并获取数据

Php 永久登录并获取数据,php,magento,curl,Php,Magento,Curl,我用这个来做loggin到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/a

我用这个来做loggin到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记录会话

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);
2) 如何使用已记录的会话从其他页面获取数据

3) 提前谢谢

试试这个:

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

这是什么意思?我只是尝试连接到magento网站,并在帐户页面中获取一些信息。你们中有人能回答相同的问题吗。?链接: