I need to use cURL to get data from a website but I need to include the session token in my request header. The problem is, the session token is stored in the browser's local storage. Since cURL is not a web browser, how can I get the session token?
EDIT: Here's my code:
define('COOKIE_FILE','cookie.txt');
$url = 'https://website.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_error || $http_code !== 200) {
return "Error!\ncUrl: $curl_error\nHTTP code: $http_code\nResult: $result";
} else {
return $result;
}