Thanks for the replies! I've been reading deeper into this and playing around with the concept for a bit and came up with something - not bulletproof or tried & true for that matter, but it appears to do the trick.
<?php session_start();
$self =$_SERVER['PHP_SELF'];
$salt = "buttery";
?>
<?php if(!isset($_POST['submit'])) {
$token = sha1(mt_rand(1,1000000) . $salt);
$_SESSION['token'] = $token;
?>
<form accept-charset="ISO-8859-1, UTF-8" method="post" action="<?php echo "$self"; ?>">
<input type="text" name="name" value="">
<input type="hidden" name="token" value="<?php echo "$token"; ?>">
<p><button type="submit" name="submit">submit</button></p>
</form>
<?php
}
if(isset($_POST['submit'])) { # form submitted
if (!isset($_POST['token']) ||
!isset($_SESSION['token']) ||
empty($_POST['token']) ||
$_POST['token'] !== $_SESSION['token']) {
die('Bad Token');
}
else {
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
unset($_SESSION['token']);
echo "$name";
}
}
?>
It's probably better if you randomly create the "salt" on the fly - but as a general example the above should work. This token is built by choosing a pseudo-random number between 1 and 1,000,000 that is concatenated to the $salt. Then we encrypt as an sha1() hash. Maybe not the best way, but it's a good starter anyway.
The form processor ensures that the values are not empty and are actually set then compares the values of the token, to the sessions value as well as what the _POST value is - to be sure they match. If the tokens do not match, the script is halted as we don't want to trust the input since it likely didn't originate from your page.
I really hope this solution helps someone else as much as i think it'll help me. If you can see some areas of improvement - by all means, point them out. Thanks!