Home  >  Article  >  Web Front-end  >  How to implement form method

How to implement form method

ringa_lee
ringa_leeOriginal
2017-07-13 17:36:131333browse

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 = &#39;<body><form action="phpcn.php" method="post" id="phpcn" name="phpcn" style="display:none"> &#39; ;
$str .= &#39;账号:<input type="text" name="username" value="&#39; . $username . &#39;" /><br />&#39; ;
$str .= &#39;密码:<input type="text" name="password" value="&#39; . $password . &#39;" /><br />&#39; ;
$str .=&#39;<input type="hidden" name="act" value="signin" /></form></body>&#39;;
$str .= &#39;<script>window.onload= function(){document.getElementById("qqform").submit();}</script>&#39;;
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 . &#39;includes/phpcn_form.php&#39;);
$form     = new form();
$username  = $j_token[&#39;username&#39;];$password=$j_token[&#39;password&#39;];
$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!

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