I have this code in a default index page:
<?php
$_SESSION['user'] = 'Bill';
print $_SESSION['user'];
$_SESSION = array();
session_destroy();
$_SESSION['user'] = 'Andy';
print $_SESSION['user'];
?>
The output is the following:
Bill
Warning: session_destroy(): Trying to destroy uninitialized session in C:\xampp\htdocs\DSP\index.php on line 15
Andy
Obviously I have to initialize the session with session_start() but these are my questions:
1) However, why can I store a session without session_start() function?
2) Now I put session_start() function on the top of the code:
<?php
session_start();
$_SESSION['user'] = 'Bill';
print $_SESSION['user'];
$_SESSION = array();
session_destroy();
$_SESSION['user'] = 'Andy';
print $_SESSION['user'];
?>
Now the output is the following:
Bill
Andy
My question now is:
3) Why Andy is printed on the output? Why compiler NOT gives me error that session must be started again beacuse I destroyed it before with the command session_destroy()?
Thanks everyone very much!