I recently looked at the session issue and needed to determine whether the user is logged on. I found that either of the following methods can be used to determine whether the user is logged on. The code is as follows: {code ...} problem: In the second judgment statement, if you only write $ _ SESSION instead of $ _ SESSION [& #039; uname & #039;], an error is reported... I recently looked at the session issue and needed to determine whether the user is logged on. I found that either of the following methods can be used to determine whether the user is logged on.
The code is as follows:
First: if (empty ($ _ SESSION) {echo 'you have not logged on. please log on';} Else {echo 'Welcome'. $ _ SESSION ['uname']. 'here is the homepage'; echo 'to exit
';} Second: if (! Isset ($ _ SESSION ['uname']) {echo 'you have not logged on yet. please log on
';} Else {echo 'Welcome'. $ _ SESSION ['uname']. 'here is the homepage'; echo 'to exit
';}
Problem: In the second judgment statement, if you only write $ _ SESSION instead of $ _ SESSION ['uname'], an error is returned. if you use the first method, there is no problem in the brackets behind empty, whether it is $ _ SESSION ['uname'] or $ _ SESSION. why? Which of the two methods is better? Or is it safer? Thank you.