PHP How to better and more effective implementation-----User Registration page

Source: Internet
Author: User
Tags config empty file upload header strlen
Page | User registration as a programmer should have been to the forum, are in the forum should be registered users. The Forum user Registration steps are divided into several:

The first step \ Agreement page, only agreed to this agreement can enter the next registration
Second step \ Form Input page, enter the user's registration information
Third Step Registration results page, prompt registration success


In the actual work, if we want to develop the implementation of this registration page, we should pay attention to a number of issues:

1\ the user skips the "first step", does not read the Protocol page, and directly accesses the form input page directly through the URL of the second step.
2\ users in the completion of the "third step", and constantly refresh the page, the user input information on every refresh time is saved again
3\ users when completing the "Third step", click Back, modify a message, submit again.


Similar to this form in the process of web development will often encounter, for the 3rd, almost all of the current forums have this problem exists, the 2nd in some message board often encountered, but how to do to avoid the above problems?


Today, the boss asked me to help others do a file upload things, allow anyone to upload the requirements file, page template has been designed, is the same as the user registration steps are the same, three steps. I have done similar things before, but the anti-refresh mechanism is not well designed. Anyway, do nothing today, just a little research, see how to implement the code can avoid the above problems.
-----------------------------------------------
-----------------------------------------------
The following is a personal design implementation code that can avoid the above problems. Access to register.php through the browser, in the input "username" and "address" time, two can not be empty, when empty, will prompt error message; When two input boxes are not empty, you can submit a successful, after the successful submission, you again to refresh and back, to see if it has reached the effect.


Document I: config.inc.php

<?php

Start session
Session_Start ();

Setting does not make local caching
Header (' Expires: '. Date (' d,d M Y h:i:s ', Mktime (0,0,0,1,1,2000)). ' 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 ');

?>


Document II: register.php

<?php

Require_once "config.inc.php";

if (Isset ($_session[step2]) && isset ($_POST[STEP2)) {
The last step in registering
$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)) {
The second step in registering
Require_once (' step2.html ');
$_SESSION[STEP2] = 1;

} else {
The first step in registering
Require_once (' step1.html ');
$_SESSION[STEP1] = 1;

}

Determine the accuracy of the data submitted by the user and the function to save the submitted data
function FormStep3 () {
$errors = Array ();
$ERRORSTR = null;

if (strlen ($_post[username]) <1) $errors [] = "The length of the username cannot be null";
if (strlen ($_post[address]) <1) $errors [] = "The length of the address cannot be null";

if (sizeof ($errors) >0) {
$errorStr. = "<br><font color=\" red\ "size=\" 2\ ">";
$errorStr. = "Information input error:";
foreach ($errors as $error)
$errorStr. = "<li> $error </li>";
$errorStr. = "</font><br><br>";
}else{
Used to hold information entered by the user to a database or other place
It's a little bit of a saving process.
}
return $errorStr;
}

?>


Template file One: step1.html

<font size= "2" ><strong> step a reading of the Constitution </strong></font><br>
<textarea name= "textarea" cols= "rows=" "4" wrap= "VIRTUAL" >
The first one does not smoke
The second one doesn't drink.
The third one doesn't eat.
</textarea>
<form name= "form3" method= "Get" action= "works.php" &

Gt
<input type= "hidden" name= "Step1" value= "1" >
<input type= "Submit" value= "I agree" >
<input type= "button" value= "I don't agree" >
</form>


Template file Two: step2.html

<strong><font size= "2" > Step two submit registration Form </font></strong><br>
<form method= "POST" action= "works.php" >
<?= $errorStr?>
<input type= "hidden" name= "Step2" value= "1" >
Enter registration name: <input type= "text" name= "username" value= "<?=htmlspecialchars ($_post[username))?>" ><br>
Input: <input type= "text" name= "Address" value= "<?=htmlspecialchars ($_post[address])?>" ><br>
<input type= "Submit" Name= "SUBMIT4" value= "submitted" >
</form>


Template file Three: step3.html

<font size= "2" ><strong> step three commit success </strong></font>



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.