Home > Backend Development > PHP Tutorial > Have questions about isset and empty?

Have questions about isset and empty?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-10-20 10:08:51
Original
904 people have browsed it

I 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'].' 这里是主页 ';

    echo '<a href="quit.php">退出</a><p>';
}

第二种:
if(!isset($_SESSION['uname'])){

    echo '您还未登录,请<a href="login.php">登录</a><p>';

}else{

    echo '欢迎'.$_SESSION['uname'].' 这里是主页 ';

    echo '<a href="quit.php">退出</a><p>';
}

</code>
Copy after login

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

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template