Cookie hold login information after successful login Setcookie is a value closed browser in the first page to read the value of the solution

Source: Internet
Author: User
Cookie Save Login After login successful Setcookie is a value closed browser in the first page to read the value of the solution
Cookies are saved at logon

if (empty ($c)) {
echo "does not exist username or password error!"; Exit
}else{
if (isset ($_post[' checked ')) && $_post[' checked ']!=0) {
Setcookie (' username ', $c [' username '],time () +60*60*24*7);
Setcookie (' id ', $c [' ID '],time () +60*60*24*7);
}
Determine if it is an AJAX request
if (Isset ($action)) {
echo "Landing success";
$_session[' user ']= $c [' username '];
}else{
$_session[' user ']= $c [' username '];
Header ("location:/");
}
}

Home judgment

Public Function Index ()
{
Session_Start ();
Print_r ($_cookie);
if (Isset ($_cookie[' id ')) && isset ($_cookie[' username ')) {
echo $_cookie[' username '];exit;
$_session[' user ']=$_cookie[' username ';
}
$this->display ();
}

Cookie value can not be found, I would like to ask this information security? How to improve.
------Solution--------------------
Cookie Usage Error
Setcookie (' username ', ' username ', Time () +60*60*24*7);
Setcookie (' id ', ' id ', time () +60*60*24*7);
------Solution--------------------
if (empty ($c)) {???
I don't know how much code you omitted before.
Since there is a conditional access to the cookie Settings branch, then you must first confirm that the branch entered and then test it?
------Solution--------------------

You see if this is done.
if (isset ($_post[' checked ')) && $_post[' checked ']!=0) {
Setcookie (' username ', ' ssssss ', Time () +60*60*24*7);
Setcookie (' id ', ' + ', Time () +60*60*24*7);
}

------Solution--------------------
Close the browser on the first page to read the value Solver
------Cookies are saved on the client and disappear as your browser shuts down.
------Solution--------------------
After successful landing, did you point out the exit and then close the browser ah? Then reopen the home page cookie is gone?
If you do not exit, it is recommended that you change other browsers to see if the same results ...
Must not login after the point of exit and then close the browser ha ~ ~
------Solution--------------------
Set the path of the cookie to look at,
  • 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.