Home  >  Article  >  Backend Development  >  How to implement PHP better and more effectively---User registration page_PHP tutorial

How to implement PHP better and more effectively---User registration page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:58:44963browse

Everyone who is a programmer should have been to the forum, and they should all be registered users of the forum. The steps for user registration on the forum are divided into several steps:
The first step is the agreement page. Only by agreeing to this agreement can you proceed to the next step of registration
Step 2: On the form input page, enter the user’s registration information
Step 3: Registration result page, prompting successful registration


In actual work, if we want to develop and implement this kind of registration page, we must pay attention to many issues:

1 The user skips the "first step", does not read the agreement page, and directly accesses the form input page through the URL of the second step.
2. When the user completes the "third step", he keeps refreshing the page, and the information entered by the user is re-saved every time he refreshes
3. When the user completes the "third step", click back, modify some information, and submit again.


Forms like this are often encountered in the process of web development. Regarding point 3, this problem exists in almost all current forums. Point 2 is often encountered in some message boards, but what to do? How can the above problems be avoided?


Today, my boss asked me to help others create a file upload tool, allowing anyone to upload files that meet the requirements. The page template has been designed, and it is the same as the user registration process, divided into three steps. I have done similar things before. But the anti-refresh mechanism is not designed very well. Anyway, I have nothing to do today, so I will do a little research and see how to implement the code to avoid the above problems.
--------------------------------------------------
--------------------------------------------------
The following is a personally designed implementation code that can avoid the above problems. When accessing register.php through a browser, when entering "username" and "address", both cannot be empty. If they are empty, an error will be prompted. Information; When both input boxes are not empty, the submission can be successful. After the submission is successful, you can refresh and go back to see if the effect is achieved.


File 1: config.inc.php


//Start session
session_start();

//Set not to perform 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');

?>


File 2: register.php


require_once "config.inc.php";

if(isset($_SESSION[step2]) && isset($_POST[step2])) {
//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])) {
//The second step of registration
require_once('step2.html');
$_SESSION[step2] = 1;

} else {

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631982.htmlTechArticleEveryone who is a programmer should have been to the forum, and they should all be registered users of the forum. Users on the forum The registration steps are divided into several parts: The first step is the agreement page. Only if you agree to this agreement can you enter...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn