Verification code in session-Thinkphp framework

Source: Internet
Author: User
Publicfunctionmyses () {import (& quot; ORG. util. date & quot;); $ Setimesession (& #39; time & #39;); $ DatenewDate; if ($ Setime! NULL) {$ diff $ Date-& gt; dateDiff (& quot; $ Setime & quot;, & quot; s & quot;); if ($ diff & gt; 10) {determine if it expires $ Setime $ Date-& gt; dateAdd ($ number framework session verification code php

Public function myses (){
Import ("ORG. Util. Date ");
$ Setime = session ('time ');
$ Date = new Date;
If ($ Setime! = NULL ){
$ Diff = $ Date-> dateDiff ("$ Setime", "s ");
If ($ diff> = 10) {// determines whether it has expired
$ Setime = $ Date-> dateAdd ($ number = 10, $ interval = "s"); // Set the Expiration Time
Session ('time', $ Setime); // Save the expiration time in the session
Session ('Rand', rand (11111,99999 ));
Echo session ('Rand ');
Echo 1111; // The session exists, but it takes more than 3 minutes to regenerate the verification code
}
Else {
Echo $ diff; echo"
";
Echo session ('time'); echo"
";
Echo session ('Rand'); echo"
";

Echo 2222; // Obtain the output ID again within 3 minutes
}
}
Else {
$ Setime = $ Date-> dateAdd ($ number = 10, $ interval = "s"); // Set the Expiration Time
Session ('time', $ Setime); // Save the expiration time in the session
Session ('Rand', rand (11111,99999 ));
Echo session ('Rand'); echo"
";
Echo session ('time'); echo"
";
Echo 3333; // The session value is not set. a new verification code is generated.
}
}

There should be no logic error. I don't know which method is wrong. because I am not familiar with the session, I want to save an expiration time in the session. If it expires, it will be regenerated. 1. help you change the above code. 2. you can implement this function better.

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.