I have a simple little homework page. It begins with an index.php, which points directly at startfile.html.php
At the top of startfile.html.php I start a $_SESSION array
<?php session_start(); $_SESSION['error'] = 'So far everything is OK.'; ?>I thought this was a global array, available to all webpages beneath startfile.html.php i.e. all my folders and webpages.
However, when I do not have session_start(); at the top of, say change_PW_form.php I do not see the error messages from $_SESSION.
For instance:
if($password != $confirm){
//return the values to the user
$_SESSION[‘email’] = $email;
//display error
$_SESSION[‘PWerror’] = ‘密码不一样 Passwords did not match’;
include ‘changePW_form.php’;
exit();
}
If I enable session_start(); at the top of all my pages, I see all the error or success messages.
BUT, then I constantly get error messages in the error_log file like this:
[Sun Feb 28 11:05:39 2021] [warn] [client 112.23.178.17] mod_fcgid: stderr: PHP Notice: A session had already been started - ignoring session_start() in /var/www/vhosts/mywebpage.com/httpdocs/test19BEcw/changePW_form.php on line 3, referer: https://mywebpage.com/test19BEcw/changePW.php
What can I do to stop these error_log messages, but keep my problem or success info messages??
Maybe I need to declare a default value for all possible $_SESSION values right at the start, not per folder and webpage??