This issue comes from a situation that may look strange, but this purpose is fully intentional.
Here is the scenario : I have 3 scripts (let's call them A, B and C). Each one has to be executed every 5 seconds, with a specific cookie.
I wanted to automate the execution of these scripts with another one called "start.php", using cURL, which should set the proper cookie before executing any of those scripts.
Summary :
- I call 'start.php' manually
- start.php sets the cookie A, then calls A.php
- Idem with B.php and C.php and proper cookies
- Repeat every 5 seconds.
Here is what my script from start.php looks like :
function startCrawling()
{
$currentChall = 1;
$cookieValue = "";
for ($currentChall = 0; $currentChall <= 3; $currentChall++) {
$sql = getConnection()->prepare("SOME STUFF HERE");
if ($sql->execute()) {
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
if ($row['idChallenge'] == $currentChall) {
$cookieValue = $row['token'];
break;
}
}
}
sendRequest($currentChall, $cookieValue);
sleep(1);
}
}
/**
* Send the request to the given script
*/
function sendRequest($id, $cookieValue)
{
$params = [
'password' => 'p4ssw0rd'
];
$defaults = array(
CURLOPT_URL => 'http://localhost/script' . $id . '.php',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
CURLOPT_HTTPHEADER => array("Cookie: AdminToken=".$cookieValue),
CURLOPT_VERBOSE => true
);
$ch = curl_init();
curl_setopt_array($ch, $defaults);
$content = curl_exec($ch);
curl_close($ch);
if ($content === false) {
echo 'Erreur Curl : ' . curl_error($ch);
}
}
BUT, at the end, even if every script has been executed, the only value sent as a cookie is the PHPSSID (seen in my requestb.in). I have been searching workarrounds for 2 days, but I can't find any similar problem on the web.
Any help would be truly appreciated.
(Edited due to comments suggestion)