The example in this article describes how PHP uses token to prevent forms from repeating submissions. Share to everyone for your reference, specific as follows:
<?php
*
* PHP uses token to prevent form recurrence
* This approach is purely for beginners reference
/session_start ();
function Set_token () {
$_session[' token '] = MD5 (Microtime (true));
function Valid_token () {
$return = $_request[' token '] = = = $_session[' token ']? true:false;
Set_token ();
return $return;
}
If token is empty, generates a token if
(!isset ($_session[' token ')) | | $_session[' token ' the]== ') {
set_token ();
}
if (isset ($_post[' test ')) {
if (!valid_token ()) {
echo "token error";
} else{
Echo ' successfully submitted, Value: '. $_post[' test ';
}
? >
<form method= "POST" action= "> <input type=" hidden "name=
" token "value=" <?php Echo $_ session[' token ']?> ' >
<input type= "text" name= "test" value= "Default" >
<input type= "Submit" Value= "Submit"/>
</form>
More interested in PHP related content readers can view the site topics: "Php Curl Usage Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.