Newbie Tom asks questions about session

Source: Internet
Author: User
Newbie Tom asks questions about the session. what I want to achieve is to prevent users from logging on repeatedly. I don't understand the advanced method. I will only use what I can understand. thank you!

First login page
If (! $ Username) {$ aa = 'account does not exist';} else if ($ password! = $ Bb) {$ aa = 'incorrect password ';} else if (! Empty ($ _ SESSION ["username"]) {$ aa = 'logged on to this account ';} else {session_start (); $ _ SESSION ["md5"] = md5 ($ time); $ _ SESSION ["username"] = $ account; DB: query ("UPDATE ". DB: table ('ABC '). "set a = '$ time', B =' {_ _ SESSION [" username "]} ', md5 = '{$ _ SESSION ['md5']}' where name = '$ account' "); $ aa = 'logged in successfully ';}

In this case, the question seems to be caused by the use of $ _ SESSION ["username"] without session_start?
If you delete} else if (! Empty ($ _ SESSION ["username"]); yes, but there are other problems.

The following is the page after logon.

Session_start (); $ md5 =$ _ SESSION ["md5"]; $ username =$ _ SESSION ["username"]; $ aa = DB :: get_one ("SELECT * FROM ". DB: table ('ABC '). "WHERE B = '$ username' and md5 =' $ md5'"); if (! $ Aa) {session_destroy (); echo "script" alert ('you are offline '); script "; echo"

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.