I have the following code which should prevent form spoofing. A token is used to match and ensure that the form submitted is from that page..
if (isset($_POST['Submit'])) {
if (!isset($_POST['token']) || $_POST['token'] != $_SESSION['token']) {
// error, form spoofing, return to users' page or do something else
echo '<script>',
'alert("Form spoofing error!! Please Try again later")',
'</script>';
} else {
//Continue with submission
}
}
The error shows up every-time I submit the form and needs to show only when there a security risk.
Thanks.
EDIT: The following code is added at the start of the page:
$_SESSION['token'] = md5(time());
A hidden field is added which matches with the token created at the start of the session after submission:
<input name="token" id="token" value="<?php echo md5(time()); ?>" type="hidden">
PHP spoofing error comes after every form submission which doesn't let me submit form.