Php 脚本结束后保留会话

Php 脚本结束后保留会话,php,session,curl,login,Php,Session,Curl,Login,我想知道是否有可能在cookie存在时保持登录,所以我只需要登录一次,即使使用不同的脚本。我在做这样的事情: $tempCookie = 'mycookiefile'; //Begins with the base URL to save cookies $ch = curl_init($url); curl_setopt($ch, CURLOPT_COOKIEJAR, $tempCookie); curl_setopt($ch, CURLOPT_COOKIEFILE, $te

我想知道是否有可能在cookie存在时保持登录,所以我只需要登录一次,即使使用不同的脚本。我在做这样的事情:

$tempCookie = 'mycookiefile';

//Begins with the base URL to save cookies
$ch = curl_init($url);        
curl_setopt($ch, CURLOPT_COOKIEJAR, $tempCookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tempCookie);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");        
curl_exec($ch);    

//Now i do the login
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 
            array('username' => $usuario, 'password' => $password));
echo curl_exec($ch); //the login works
现在我做我的工作从url获取数据。 我可以跳过所有的登录过程,只做一次吗?例如,当我们关闭浏览器窗口,返回时,我们仍在登录。

,可能会对您有所帮助,没有尝试,但很好奇,如果它有效,请将解决方案作为答案发布。