<div style="width: 100px; float: left">Security key:</div><input type="text" name="skey" id="skey" size="5" /> <img id="skeyimage" src="http://dev.network-13.com/news/image.php" title="Security key" /><br />
<?php
session_name('n13news');
session_start();
include_once 'db.php';
include_once 'config.php';
function showform(){
echo "<form method=\"post\" action=\"\" />";
echo "Captcha: <input type=\"text\" name=\"captcha\" /> <img src=\"imagenew.php\" /> ";
echo "<input type=\"submit\" name=\"submitbutton\" value=\"Submit\" />";
echo "</form>";
}
if(!$_POST['submitbutton']){
//if the form hasn't been submitted show it.
showform();
}else{
//now we check if the captcha entered matches the image
$captcha = $_POST['captcha']; //grab the text the user entered
$captcha = md5($salt . $captcha); //salt and md5 it
if($captcha == $_SESSION['image_random_value']){
//clear image_random_value to stop the user submitting the form multiple times by F5'ing
unset($_SESSION['image_random_value']);
echo "success";
//the captcha is correct, do whatever you want here
}else{
//capcha is wrong, show form again with an error message
echo "Wrong captcha <br />";
showform();
}
}
?>