I am currently building a small script for cron jobs, i am testing everything in the terminal (Linux) and i cant figure out why sessions are not working properly.
session_start()
$_SESSION['cron'] = 'test';
echo $_SESSION['cron'];
I am currently building a small script for cron jobs, i am testing everything in the terminal (Linux) and i cant figure out why sessions are not working properly.
session_start()
$_SESSION['cron'] = 'test';
echo $_SESSION['cron'];
This is my solution
private function get($key){
$content = @file_get_contents( __DIR__ . '/../../cron/data.json' );
if ($content) {
$content = json_decode($content, true);
if ( is_array($content)) {
return $content[$key];
}else{
return false;
}
}else{
return false;
}
}
private function request($key){
$content = @file_get_contents( __DIR__ . '/../../cron/data.json' );
if ($content) {
$content = json_decode($content, true);
if ( is_array($content)) {
$content[$key] = time();
file_put_contents( __DIR__ . '/../../cron/data.json' , json_encode($content) );
}else{
return false;
}
}else{
file_put_contents( __DIR__ . '/../../cron/data.json' , json_encode(['demo' => time()]) );
}
}