Home>

This question was asked during an empire interview:how to deal with the problem of repeated post submissions, Later communicated [email protected],He said record time,I did not understand,What I want is to use session to record on the form page,Then submit the page to judge,If equal, it is considered successful,And clear the session, but there is a problem if the form page is html, what should I do?Or do i want to adjust a PHP verification page?Similar to the function of verification code. Others use the header to set the expiration time... but did not try. The following is what I wrote in php, tested and available.

<?Php
// Open session
session_start ();
</p>
<p>
// if there is a submission ID
if (isset ($_ get ["action"])&$_get ["action"] === "save") {
</p>
<p>
// Commit only if there is a session and the same value
if (isset ($_ session ["__ open_auth"])&&isset ($_ post ["auth"])&&$_session ["__ open_auth"] == $_post ["auth"]) {
print_r ($_ post);
$_session ["__ open_auth"]=null;// clear
} else {
</p>
<p>
//let's go
header ("location:post.php");
}
exit ();
}
</p>
<p>
// authorize
$auth=$_session ["__ open_auth"]=time ();
</p>
<p>
?>
<! Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>post</title>
</head>
<body>
<form action="post.php?Action=save" method="post">
<ul>
<li>
<input type="hidden" name="auth" value="&?;php echo $auth;?>">
<input type="text" name="username">
</li>
<li>
<input type="password" name="userpass">
</li>
<li>
<input type="submit" value="Go Up">
</li>
<li>
<?Php echo time ();?>
</li>
</ul>
</form>
</body>
</html>
php
  • Previous JavaScript example sharing --- special effects with three-dimensional image
  • Next Some tips on JavaScript namespaces
  • Trends