Have questions about isset and empty?
Oct 22, 2016 am 12:00 AMI was looking at session issues recently and needed to determine whether the user was logged in. I found that the following two methods can successfully determine whether the user is logged in.
The code is as follows:
<code>第一种: if(empty($_SESSION)){ echo '您还未登录,请<a href="login.php">登录</a><p>'; }else{ echo '欢迎'.$_SESSION['uname'].'&nbsp;这里是主页&nbsp;'; echo '<a href="quit.php">退出</a><p>'; } 第二种: if(!isset($_SESSION['uname'])){ echo '您还未登录,请<a href="login.php">登录</a><p>'; }else{ echo '欢迎'.$_SESSION['uname'].'&nbsp;这里是主页&nbsp;'; echo '<a href="quit.php">退出</a><p>'; } </code>
Question: In the second judgment statement, if you only write $_SESSION instead of $_SESSION['uname'], an error will be reported. If you use the first method, whether it is $_SESSION['uname in the brackets after empty '] or $_SESSION are no problem, what is the reason? Which of the two methods is better? Or is it safer? Thank you

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
