
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 0.94 KB | hits: 21 | expires: Never
Form post security. Making sure it did not come from outside source
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
<input type="text" name="post" id="post" />
<input type="submit" name="submit" id="submit" />
</form>
<?php
session_start(); // don't forget that you need to call before output (place first, or use ob_start()
$_SESSION['formhash'] = md5(date('Y-m-d H:i:s').'2fiaSFI#T8ahugi83okkj');
?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
<input type="text" name="post" id="post" />
<input type="hidden" name="hash" id="hash" value="<?php echo $_SESSION['formhash']; ?>" />
<input type="submit" name="submit" id="submit" />
</form>
<?php
session_start(); // don't forget that you need to call before output (place first, or use ob_start()
if (isset($_SESSION['formhash']) && isset($_POST['hash']) && $_SESSION['formhash']==$_POST['hash']) {
// treat $_POST
}
?>