How to ensure that cookies are not falsified when using cookies to save logged-in user information

Source: Internet
Author: User
Tags setcookie
How to ensure that cookies are not forged when using cookies to save logged-in user information
You master. Ask you a question, I would like to use a cookie to save the user login, the purpose is to use the HTML page (display user name and automatically fill in the text box), and to be able to login for a period of time.
Excuse me, please. How can I guarantee that a cookie will not be forged?

------Solution--------------------
Select Remember password to log in when
$spuerpass = "20120412001@#"//self-change, user cannot get
$user _id= $rows _arr[' user_id ';
$rand =MD5 (MD5 ($user _id. $spuerpass));
Setcookie (' User_, $user _id, (Time () +2592000), '/', ', 0);
Setcookie (' Rand ', $rand, (Time () +2592000), '/', ', 0);
$_session[' user_id ']= $user _id;


Next open the page to detect if there is a remember password login
if (Isset ($_cookie[' user_id ') &&isset ($_cookie[' rand '))
{
$user _id=$_cookie[' user_id '];
$spuerpass = "20120412001@#";
$rand =MD5 (MD5 ($user _id. $spuerpass));
if ($_cookie[' rand ']== $rand)
{
$_session[' user_id ']= $user _id;
}
}
  • Related Article

    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.