Home >Web Front-end >JS Tutorial >How to implement form method
Automatic submission of form forms is also a problem we encounter in regular projects.
For example, in the mall system we often see, if the user is a seller and wants to log in to the user seller's backend, our normal logic does not require the user to log in again, so we can use Automatically log in to the form, which is the automatic submission function.
Let me briefly explain it to you:
The general idea is: where ordinary members can log in, the user name, password and user ID can be saved after successful login. For security reasons, we can use AES encryption and store it in cookies. When the user visits the seller's backend management page, we can determine the information in the stored cookie in the program and determine whether it is a seller. If it is a seller, we You can use the form to automatically log him in.
Simply take the automatic submission function of ecshop as an example:
Create a phpcn_form.php under includes:
<?php class form{ public function hform($username,$password){ $str = '<body><form action="phpcn.php" method="post" id="phpcn" name="phpcn" style="display:none"> ' ; $str .= '账号:<input type="text" name="username" value="' . $username . '" /><br />' ; $str .= '密码:<input type="text" name="password" value="' . $password . '" /><br />' ; $str .='<input type="hidden" name="act" value="signin" /></form></body>'; $str .= '<script>window.onload= function(){document.getElementById("qqform").submit();}</script>'; echo $str; exit; } }?>
In the signin method of phpcn.php, perform aes Decrypt and introduce the phpcn_form.php file.
<?php require_once(ROOT_PATH . 'includes/phpcn_form.php'); $form = new form(); $username = $j_token['username'];$password=$j_token['password']; $a = $form->hform($username,$password);exit; ?>
With a few simple lines of code, you can quickly implement the function of automatically submitting the form for login, so that the user only needs to log in once. Isn't it very simple? Everyone is welcome to comment, and we can learn and make progress together on the road of programming.
The above is the detailed content of How to implement form method. For more information, please follow other related articles on the PHP Chinese website!