How to better and more effectively implement PHP-user registration page. When programmers have been to forums, they should have registered forum users. the steps for registering users on the forum are divided into several steps: the first step is the agreement page. only those who agree to this agreement can be included in the forum where programmers should all go to the forum, all users should have registered forum users. the steps for registering users on the forum are as follows:
On the first step agreement page, you can only register with this agreement
Step 2 enter the user registration information on the form input page
Step 3: The registration result page prompts that the registration is successful.
In actual work, if we want to develop and implement such a registration page, we should pay attention to many problems:
1. if you skip step 1 without reading the protocol page, you can directly access the form input page through the url in step 2.
2. when the user completes step 3, the page is repeatedly refreshed, and the information entered by the user is retained once every time the user refreshes the page.
3. when the user completes step 3, click back to modify a message and submit it again.
Similar forms are frequently encountered in web development. for the 3rd point, this problem exists in almost all forums. 2nd points are often encountered in some message boards, but how can we avoid the above problems?
Today, the boss asked me to help others upload files and promised anyone to upload the files that meet the requirements. the page template has been designed, which is the same as the steps for user registration. it is divided into three steps. I have done similar things before, but the anti-refresh mechanism is not well designed. if there is nothing to do today, let's take a look at it and see how to implement the code to avoid the above problems.
-----------------------------------------------
-----------------------------------------------
The following is the personal implementation code to avoid the above problems. access register through a browser. php, when you enter "user name" and "address", both of them cannot be blank. if it is blank, an error message is displayed. when neither of the input boxes is blank, you can submit the job successfully. after the job is submitted, refresh the job and roll back the job to see if the job has been completed.
File 1: config. inc. php
// Start the session
Session_start ();
// Set not to cache locally
Header ('expires: '. date ('d, d m y h: I: S', mktime (,). 'gmt ');
Header ('last-Modified: '. gmdate ('d, d m y h: I: s'). 'gmt ');
Header ('cache-control: private, no-Cache, must-revalidate ');
Header ('pragma: no-cache ');
?>
File 2: register. php
Require_once "config. inc. php ";
If (isset ($ _ SESSION [step2]) & isset ($ _ POST [step2]) {
// The last step of registration
$ ErrorStr = formStep3 ();
If ($ errorStr! = Null ){
Require_once('step2.html ');
} Else {
Require_once('step3.html ');
Unset ($ _ SESSION [step2], $ _ SESSION [step1]);
}
} Else if (isset ($ _ SESSION [step1]) & isset ($ _ GET [step1]) {
// Step 2 of registration
Require_once('step2.html ');
$ _ SESSION [step2] = 1;
} Else {
Refer to the step 1 Agreement page. only when you agree to this agreement can you enter...