You get the error : Warning: array_push() expects parameter 1 to be array, null given
because your $_SESSION['messages']
variable is never set.
When this part of your code gets executed,
session_start();
if (session_status() == PHP_SESSION_NONE) {
$_SESSION['messages'] = array();
}
The first line starts a new session. So session_status() == PHP_SESSION_NONE
will never be true
since session_status()
returns 2 and PHP_SESSION_NONE
equals to 1. As a result, $_SESSION['messages'] = array(); will not get executed.
What you need to be doing is, check if a session has been started, and start one if not.
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
This will check if you have a session_start() called somewhere earlier in your script.
Then after that, add this line:
if(!isset($_SESSION['messages']))
$_SESSION['messages'] = array();
Hope it helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…