On a new page, how does one obtain the username that has been logged in?

Source: Internet
Author: User
In this case, $ _ COOKIE [& #039; username & #039;] cannot print the login user name. What should I do with this user name? The login page {code...} is like this $ _ COOKIE ['username']. The Login User name cannot be printed. What should I do with this user name?

Logon page


  Prepare ("select id, username, password from user where username =? And password =? "); $ Stmt-> execute (array ($ _ POST ['username'], ($ _ POST ['Password']); if ($ stmt-> rowCount ()> 0) {list ($ id, $ username) = $ stmt-> fetch (PDO: FETCH_NUM); $ time = time () + 24*60*60; setCookie ("uid", $ id, $ time, "/"); setCookie ("username", $ username, $ time, "/"); setCookie ("isLogin", 1, $ time, "/"); echo 'script location = "blog. php "script" ';} else {echo "Logon Failed" ;}}?>

Reply content:

In this way, $ _ COOKIE ['username'] cannot print the login user name. What should I do with this user name?

Logon page


  Prepare ("select id, username, password from user where username =? And password =? "); $ Stmt-> execute (array ($ _ POST ['username'], ($ _ POST ['Password']); if ($ stmt-> rowCount ()> 0) {list ($ id, $ username) = $ stmt-> fetch (PDO: FETCH_NUM); $ time = time () + 24*60*60; setCookie ("uid", $ id, $ time, "/"); setCookie ("username", $ username, $ time, "/"); setCookie ("isLogin", 1, $ time, "/"); echo 'script location = "blog. php "script" ';} else {echo "Logon Failed" ;}}?>

You must first write the COOKIE upon successful login, and then access the new page after writing, so that your php code can read it.

No one ..........

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.