您好,我在尝试将 cookie 存储在 txt 文件中时遇到问题。my_cookies.txt 是该文件同一文件夹中的一个 txt。
我想在登录之前和之后管理 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;
?>
感谢您的帮助=),我希望您可以做任何事情来帮助我:(