Provides various official and user-released code examples. For code reference, you are welcome to learn thinkphp3.2 registration and activation account password retrieval implementation.
The following describes how to activate the account and password retrieval:
Activate an account. I will give an activation code when registering it like this.
$ Jhm = $ reg-> jhm = time (). $ reg-> email;
$ Url = "http: // $ host/Member/regjhm/jhm /". base64_encode ($ jhm); // concatenate $ url; Save the activation code to the database and send the activation address to the member's email address when sending the email:
Members click this link to activate the service.
Send the url to the member's email address with the same password.
The following shows the key code:
Public function register () {// Member registration
If (IS_POST ){
$ Reg = M ('member ');
If ($ reg-> create ()){
$ Reg-> create_time = time ();
$ Host = $ _ SERVER ['HTTP _ host']; // URL
$ Jhm = $ reg-> jhm = time (). $ reg-> email;
$ Url = "http: // $ host/Member/regjhm/jhm/". base64_encode ($ jhm); // splice $ url;
If (sendMail ($ reg-> email, $ reg-> name, $ reg-> pwd, $ url )){
$ Reg-> pwd = md5 ($ reg-> pwd); // encrypted and stored in the database
$ Data = $ reg-> add ();
} Else {
$ This-> error ('email sending failed! ');
}
If ($ data! = False ){
Echo 1;
} Else {
Echo 0;
}
} Else {
$ This-> error ($ res-> getError ());
}
} Else {
$ This-> display ();
}
}
Activation:
Public function regjhm ($ jhm) {// If the activation code is consistent, the system prompts that the activation is successful. Now, the activation code does not use clearing the database activation code field.
// Base64_decode ($ jhm );
$ Member = M ('member ');
$ Jhm = base64_decode ($ jhm); // decrypt
$ Data = $ member-> where ()-> getField ('jhm '); // comparison
If ($ data ){
$ Res = $ member-> where (array ('jhm '=> $ jhm)-> setField ('jhm ',''); // clear it here. It is helpful when you log on. If the activation code does not exist, it indicates that the activation code exists, indicating that the logon is not activated.
If ($ res ){
$ This-> success ('account activated successfully! ', U ('Member/login '));
} Else {
$ This-> error ('account activation failed! ');
}
} Else {
$ This-> error ('account activated! ', U ('Member/login '));
}
}
Password Reset:
Public function resetpwd ($ email ){
$ Member = M ('member ');
$ Pwd = md5 (I ('pwd '));
If (IS_POST ){
$ Data = $ member-> where (array ('email '=> $ email)-> setField ('pwd', $ pwd); // update the password
If ($ data! = False ){
Echo 1;
} Else {
Echo 0;
}
} Else {
// Print_r ($ email );
// Exit;
$ Email = base64_decode ($ email );
$ This-> email = $ email;
$ This-> display ();
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB