I'm about to write some code for mahara. I'm trying to store a variable in a cookie. If I do, it will disappear on the next page.
Example:
foo.php:
...
$myfoo = 'bar';
setcookie('mycookie', $myfoo)
var_dump($_COOKIE)
...
executing foo.php: all the mahara cookies & 'mycookie' is set. Like expected, everything's fine.
bar.php
...
var_dump($_COOKIE)
...
executing bar.php after foo.php: only mahara standard cookies set, but no 'mycookie'.
I can't really explain that.
Also $_SESSION does not work like intended.
My server is set up correctly, cookies generally work.
Has anyone an idea?
Edit: I see the cookies via var_dump in my foo.php. Even if I stop to set them. They are there. But not on other pages.
<?php
$myfoo = 'bar';
setcookie('mycookie', $myfoo, time() + (86400 * 30), "/"); // 86400 = 1 day
var_dump($_COOKIE);
?>
Your cookies are expiring because Specifies when the cookie expires because if expiry time is omitted or set to 0, the cookie will expire at the end of the session (when the browser closes). Change it to some value like time()+86400*30
For more details: https://www.w3schools.com/php/func_network_setcookie.asp