Questions about Isset and empty?

Source: Internet
Author: User
Recently looking at the session of the question, you need to determine whether the user login, I found the following 2 ways to successfully determine whether to log on the issue.
The code is as follows:

第一种:if(empty($_SESSION)){    echo '您还未登录,请登录

';}else{ echo '欢迎'.$_SESSION['uname'].' 这里是主页 '; echo '退出

';}第二种:if(!isset($_SESSION['uname'])){ echo '您还未登录,请登录

';}else{ echo '欢迎'.$_SESSION['uname'].' 这里是主页 '; echo '退出

';}

Question: In the second Judgment statement, if you write only $_session instead of $_session[' uname ', you will get an error, and if you use the first method, either $_session[' uname ' in the parentheses behind the empty or $_ The session is no problem, what is the reason? Which of the two methods would be better? Or is it a little safer? Thank you

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.