您好,我尝试将cookie存储在txt文件中时出现问题。 my_cookies.txt是该文件的同一文件夹中的一个txt文件。使用cUrl管理cookie
我想登录前后管理的cookie,在这个例子中的Facebook 然后我想插入的cookie数据库中的,但首先我需要把它放在一个.txt或至少保存
显然,电子邮件和密码不要那些。 =)
<?php
/* STEP 2. define path of form_action */
$url = "https://facebook.com/login.php?login_attempt=1";
$email = "nn";
$password = "nn";
/* STEP 3. create a connection with curl, give post information and save cookies */
$handler = curl_init();
//insert in the handler the path
curl_setopt($handler, CURLOPT_URL, $url);
//insert in the handler parameters of post
curl_setopt($handler, CURLOPT_POSTFIELDS,'email='.urlencode($email).'&pass='.urlencode($password));
//insert in the handler option to allow sending post information
curl_setopt($handler, CURLOPT_POST,1);
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
//load and save cookies generates in temp file
curl_setopt($handler, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($handler, CURLOPT_COOKIEFILE, "my_cookies.txt");
//catch information
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true);
//define agent
curl_setopt($handler, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0");
$response = curl_exec ($handler);
curl_close($handler);
echo $response;
?>
感谢您的帮助=),我希望你可以做任何事情来帮助我:(
谢谢你的回答。 我试着用__DIR__但系统不保存我的txt文件中的信息。 你还有别的想法吗? =) – GDedieu92
我需要的是保存所有cookie,当我发送请求时,某些域响应我 – GDedieu92
@ GDedieu92如果您设置Cookie Jar /文件路径正确,cURL将为您存储Cookie。您可以打开文件并查看。看看它是否包含你期望的。 – CodeAngry