Here is the piece of code:
session_name('somename');
session_start();
echo 'session name:'.session_name();
The above does print the session name as somename. If I append the code below,
if(isset($_COOKIE['somename'])) {
echo "<br/><br/>"."Cookie somename not yet set";
}
else {
echo "<br/><br/>".var_dump($_COOKIE['somename']);
}
The output is always
Cookie somename not yet set.
Am I using the isset function wrong?
If I just append this:
echo "<br/><br/>".var_dump($_COOKIE['somename']);
Then, the output for the first time is:
session name:somename
Notice: Undefined index: somename in /path/to/file.php on line 12 NULL
If I refresh the page, then the output is
session name:somename
string(26) "367jr029jj17mdu5fgkfgiv0u6"
Isn't the cookie variable supposed to get set before the page content is loaded? or Have I not understood sessions/cookies?