- Joined
- Apr 29, 2005
- Messages
- 6,400
- Reaction score
- 130
I'm making a reply script at the moment which requires you to enter a security code to prevent spamming.
this is the script I use for it:
The problem is that the $scode that is being echoed, and the $scode in the if-statement. Aren't the same, because it apparently rands again in the if-statement. I've tried $_GET['$scode'] But that didn't really work.
Any suggestions?
this is the script I use for it:
PHP:
<?php
$scode = rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9);
if(!isset($_POST['submit'])) {
?>
<div>
<form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method ="post">
Name:
<br/><input name="name" size="20" type="text" align="left" maxlength="20">
<br/>
Enter the security code:
<br/><input name ="code" size="20" type="text" align="left"><?php echo"$scode";?>
<br/>
Message:
<br/>
<textarea name="message" rows="5" cols="50"> Adding comments hasn't been enabled yet.</textarea>
<input type="submit" name="submit" value="Go">
</form>
</div>
<?php
} else {
if($_POST['code'] == $scode) { ...rest of script} else {echo "Wrong security code";)
The problem is that the $scode that is being echoed, and the $scode in the if-statement. Aren't the same, because it apparently rands again in the if-statement. I've tried $_GET['$scode'] But that didn't really work.
Any suggestions?