Jump to content

Recommended Posts

Hello,

 

Basically, I'm using srand to generate a number, and if the user gets a specific number, they can win by entering their details into the form.

 

However, I want to block other numbers except from (in this example) 300000. I'm using:

 

<form method="POST" id="form1" name="form1" action="send.php">
Email:<input type="text" id="name" name="email"><br />
<input type="hidden" value="<?php echo $b ?>" name="name" id="name" />
<input type="hidden" value="<? echo $random_number ?>" name="code" id="code" />
<br /><input type="submit" name="submit" value="Submit my code">
</form>

 

With:

 

<?php
session_start(); 
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_POST["code"]) && $_SESSION["code"] == $_POST["code"]) {
$blacklisted = Array("300000", "##", "##", "##", "##", "##");
$code = $_POST['code'];
if( !in_array( strtolower($code), $blacklisted ) ) {
$emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>';	
} else { 
require('send.php'); 	
}   
}}
?>

 

However, any number entered seems to require send.php.

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/252836-number-guess-form-submission/
Share on other sites

<?php
session_start(); 
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_POST["code"]) && $_SESSION["code"] == $_POST["code"]) {
$blacklisted = Array("796574", "7", "2", "3", "4", "5");
$code = $_POST['code'];
if( in_array( strtolower($code), $blacklisted ) ) {
$emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>';	
} else { 
require('send.php'); 	
}   
}}
?>

 

Still getting through - thanks for assistance.

With this code I get "incorrect" - is that not what you wanted?

$blacklisted = Array("796574", "7", "2", "3", "4", "5");
//$code = $_POST['code'];
$code = 2;
if( in_array( strtolower($code), $blacklisted ) ) {
//$emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>';
echo 'incorrect';
} else { 
//require('send.php'); 
echo 'correct';
}

Must be a form issue:

 

<?php
session_start(); 
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_POST["code"]) && $_SESSION["code"] == $_POST["code"]) {
$blacklisted = Array("796574", "7", "2", "3", "4", "5");
//$code = $_POST['code'];
$code = 2;
if( in_array( strtolower($code), $blacklisted ) ) {
//$emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>';
echo 'incorrect';
} else { 
//require('send.php'); 
echo 'correct';
}}}
?>

 

still goes through ;/

Okay I think I know what you are trying to do. I've rewritten your script, does this do what you want?

session_start(); 

$_SESSION['code'] = 79;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$blacklisted = array(796574, 7, 2, 3, 4, 5);

if (isset($_POST['code'])) {
	$code = $_POST['code'];

	if (!in_array($code, $blacklisted) && $_SESSION['code'] == $code) {
		echo 'correct';
	} else {
		echo 'incorrect';
	}
}
}

echo '<form action="test.php" method="post">
<input type="text" name="code" /><input type="submit" name="submit" value="submit" />
</form>';

Always the number 300000? That makes it substantially simpler.

if ($_SERVER['REQUEST_METHOD'] === 'POST') {		
if (isset($_POST['code'])) {
	$code = $_POST['code'];

	if ($code == 300000) {
		echo 'correct';
	} else {
		echo 'incorrect';
	}
}
}

echo '<form action="test.php" method="post">
<input type="text" name="code" /><input type="submit" name="submit" value="submit" />
</form>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.