Hi,
I have a form which the user fills in and gets submitted to a PHP back end script which then does some fairly CPU- intensive activites.
To try and prevent an attacker from just constantly calling the back end script and perhaps bringing down my server, have the following code in my back end script:
And in my front- end form
The problem is that this does not always work properly- especially it seems in Safari; the posted token and session token somehow do not always match (I am logging the output of these vars and can see it dying)
Now, 2 questions:
1) Do I even need this code?
2) Any ideas what is going on here?
Thanks
I have a form which the user fills in and gets submitted to a PHP back end script which then does some fairly CPU- intensive activites.
To try and prevent an attacker from just constantly calling the back end script and perhaps bringing down my server, have the following code in my back end script:
PHP:
<?php
session_start();
if( empty($_POST['token']) || $_POST['token'] != $_SESSION['token'] )
die;
?>
And in my front- end form
PHP:
<?php
session_start();
$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;
?>
<form method="post">
<stuff>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
</form>
The problem is that this does not always work properly- especially it seems in Safari; the posted token and session token somehow do not always match (I am logging the output of these vars and can see it dying)
Now, 2 questions:
1) Do I even need this code?
2) Any ideas what is going on here?
Thanks