function 3rd_party(){
$cookie_path = __DIR__ . '/cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'xyz.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
$headers = array();
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7';
$headers[] = 'Accept-Language: en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7';
$headers[] = 'Connection: keep-alive';
$headers[] = 'Sec-Fetch-Dest: document';
$headers[] = 'Sec-Fetch-Mode: navigate';
$headers[] = 'Sec-Fetch-Site: none';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
$headers[] = 'Sec-Ch-Ua: \"Not-A.Brand\";v=\"99\", \"Chromium\";v=\"124\"';
$headers[] = 'Sec-Ch-Ua-Mobile: ?0';
$headers[] = 'Sec-Ch-Ua-Platform: \"Linux\"';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo(file_get_contents($cookie_path));
}
It says:
Warning: file_get_contents(/storage/emulated/0/htdocs/cookies.txt):
Failed to open stream: No such file or directory in
/storage/emulated/0/htdocs/k.php on line 31
and from second request it start returning data but previous one like when i run it second time it return cookie that received from 1st request
The problem is that it don’t save cookie even i closed curl
What is the solution
When i check cookies after function close it works but not working when check from inside function