保持在读取的文件中创建的 cookie 仍然存在于下一个读取的其他文件中 php
Keep the cookies that are made on a file read still exist in the next other file read php
所以我想用 https://www.mangaeden.com/api/mymanga (I call this "first file") to retrieve my personal data (e.g. my favorite comic, etc.) in JSON format, but to do that I have to login from https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx 中的 PHP 进行 API 调用(我称之为 "second file"),该文件包含一个用于存储 cookie 的程序,其中包含我从 URL 参数中提供的用户名和密码。
当我运行第一个带有cURL函数的文件发送header时,成功发送了还包含cookie数据(包括我的用户名和密码)的header,但是在那之后我调用第二个文件发送我的个人数据,cookie 不存在所以我的数据文件没有出现。
function run_set_cookie_function_inside_this_file($file_url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_exec($ch);
curl_close($ch);
}
// if this file is executed, the user's username and password will be stored in cookies
run_set_cookie_function_inside_this_file("https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx");
// this file requires user's username and password which stored in cookies to return other data (example: user's favorite movie, pet, etc.)
echo file_get_contents("https://www.mangaeden.com/api/mymanga/");
注意:这2个文件(第一个和第二个文件)不是我的,所以我不能更改里面的程序代码
这是我的问题,所以我的问题是 如何让第一个文件中制作的 cookie 仍然存在于第二个文件中?
对不起,我的英语不好,句子乱七八糟,难以理解。
非常感谢您的帮助!
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx');
curl_setopt($ch, CURLOPT_COOKIE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.mangaeden.com/api/mymanga/');
curl_setopt($ch, CURLOPT_COOKIE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$output = curl_exec($ch);
echo $output;
curl_close($ch)
我有这样的东西,第一次用 curl 登录,第二次用 api 请求!
所以我想用 https://www.mangaeden.com/api/mymanga (I call this "first file") to retrieve my personal data (e.g. my favorite comic, etc.) in JSON format, but to do that I have to login from https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx 中的 PHP 进行 API 调用(我称之为 "second file"),该文件包含一个用于存储 cookie 的程序,其中包含我从 URL 参数中提供的用户名和密码。
当我运行第一个带有cURL函数的文件发送header时,成功发送了还包含cookie数据(包括我的用户名和密码)的header,但是在那之后我调用第二个文件发送我的个人数据,cookie 不存在所以我的数据文件没有出现。
function run_set_cookie_function_inside_this_file($file_url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_exec($ch);
curl_close($ch);
}
// if this file is executed, the user's username and password will be stored in cookies
run_set_cookie_function_inside_this_file("https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx");
// this file requires user's username and password which stored in cookies to return other data (example: user's favorite movie, pet, etc.)
echo file_get_contents("https://www.mangaeden.com/api/mymanga/");
注意:这2个文件(第一个和第二个文件)不是我的,所以我不能更改里面的程序代码
这是我的问题,所以我的问题是 如何让第一个文件中制作的 cookie 仍然存在于第二个文件中?
对不起,我的英语不好,句子乱七八糟,难以理解。 非常感谢您的帮助!
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.mangaeden.com/ajax/login/?username=xxx&password=xxx');
curl_setopt($ch, CURLOPT_COOKIE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.mangaeden.com/api/mymanga/');
curl_setopt($ch, CURLOPT_COOKIE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$output = curl_exec($ch);
echo $output;
curl_close($ch)
我有这样的东西,第一次用 curl 登录,第二次用 api 请求!