Jump to content

valadating random number


redarrow

Recommended Posts


Got any idears why this wont work please cheers.


<?php

$list = array("1","2","3","4","5","6","7","8","9","0",);

for ($i = 1; $i <= 6; $i++) {
$generated_code .= $list[rand(0,9)];

}

echo $generated_code;




$crack=($_POST['crack']);



if(!$_POST['submit']){

if($crack==$generated_code){

echo"You entered the correct code!";

}else{

echo "incorrect code!";

}

}

?>

<html>
<body>
<form method="post" action="">
<input type="text" name="crack">
<input type="submit" value="send">
</form>
</html>
</body>
Link to comment
Share on other sites

[code]
<?php

$list = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" );

for( $i = 1; $i <= 6; $i++ ) {
      $rand = rand( 0, 9 );
      $generated_code .= $list[$rand];
}

echo $generated_code;

if( $_POST['submit'] )
{
      $crack= $_POST['crack'];

      if( $crack == $generated_code )
      {
            echo "You entered the correct code!";
      }
      else
      {
            echo "incorrect code!";
      }
}

?>

<html>
<body>
<form method="post" action="">
<input type="text" name="crack">
<input type="submit" value="send">
</form>
</body>
</html>[/code]
Link to comment
Share on other sites

[code]<?php

$list = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" );

for( $i = 1; $i <= 6; $i++ ) {
      $rand = rand( 0, 9 );
      $generated_code .= $list[$rand];
}

echo $generated_code;

if( $_POST[validate] )
{
      $crack = $_POST[crack];

      if( $crack == $generated_code )
      {
            echo "<br><br>You entered the correct code!";
      }
      else
      {
            echo "<br><br>incorrect code!";
      }
}

?>

<html>
<body>
<form method="post">
<input type="text" name="crack">
<input type="submit" name="validate" value="send">
</form>
</body>
</html>
[/code]

you didnt name the submit button
Link to comment
Share on other sites

redarrow your code doesn't work because as was mentioned by whale, you did not name your submit button, and also you only set your script to check if they codes match if the user has not clicked on submit button yet. Remove the ! and name your submit button

if ([color=red]![/color]$_POST['submit']) { ... }

and

<input type="submit" value="send" [color=red]name='submit'[/color]>

Link to comment
Share on other sites

this is the code in the link try


<?php

$list = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" );

for( $i = 1; $i <= 6; $i++ ) {
     $rand = rand( 0, 9 );
     $generated_code .= $list[$rand];
}

echo $generated_code;

if( $_POST[validate] )
{
     $crack = $_POST[crack];

     if( $crack == $generated_code )
     {
           echo "<br><br>You entered the correct code!";
     }
     else
     {
           echo "<br><br>incorrect code!";
     }
}

?>

<html>
<body>
<form method="post">
<input type="text" name="crack">
<input type="submit" name="validate" value="send">
</form>
</body>
</html>
Link to comment
Share on other sites

change it to this:
[code]
<?php
if($_POST[validate] ) {
      $crack = $_POST[crack];

      if( $crack == $generated_code )
      {
            echo "

You entered the correct code!";
      }
      else
      {
            echo "

incorrect code!";
      }
} else {
$list = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" );

for( $i = 1; $i <= 6; $i++ ) {
      $rand = rand( 0, 9 );
      $generated_code .= $list[$rand];
}

echo $generated_code;

}


?>

<html>
<body>
<form method="post">
<input type="text" name="crack">
<input type="submit" name="validate" value="send">
</form>
</body>
</html>
[/code]
Link to comment
Share on other sites

I will explain the method you are doing:

1. you generate the code
2. you submit a code
3. a new code is generated
4. the submited code checks if it is the same as the new generated code (this is different to the number echoed before the form)
5. you got like a billion to 1 chance of guessing the number.. lol
Link to comment
Share on other sites

[quote author=redarrow link=topic=99080.msg390072#msg390072 date=1151744878]
can it be solved with using sessions i wonder.
[/quote]

easiest way to do it is do a query to insert into a table which stores the users ip address and the random number.

then when you submit it checks the database for the code and the same ip address

if no match is found it echos wrong, otherwise correct
Link to comment
Share on other sites

okay revised code:
[code]
<?php
if($_POST['validate'] ) {
      $crack = $_POST['crack'];
      $generated_code = $_POST['generated_code'];
      if( $crack == $generated_code )
      {
            echo "

You entered the correct code!";
      }
      else
      {
            echo "

incorrect code!";
      }
} else {
$list = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" );

for( $i = 1; $i <= 6; $i++ ) {
      $rand = rand( 0, 9 );
      $generated_code .= $list[$rand];
}

echo $generated_code;

}


?>
<html>
<body>
<form method="post">
<input type="text" name="crack">
<input type='hidden' name='generated_code' value='<?= $generated_code ?>'>
<input type="submit" name="validate" value="send">
</form>
</body>
</html>

[/code]
Link to comment
Share on other sites

Crayon Violent 

the code you posted is so good but becouse the value matches the echo success is always lol

brain teaser man lol............


there is a way to get a generated number to match via a form on one page but how sessions maybe
dont no but does exist promise
Link to comment
Share on other sites

[quote author=mrwhale link=topic=99080.msg390075#msg390075 date=1151745078]
[quote author=redarrow link=topic=99080.msg390072#msg390072 date=1151744878]
can it be solved with using sessions i wonder.
[/quote]

easiest way to do it is do a query to insert into a table which stores the users ip address and the random number.

then when you submit it checks the database for the code and the same ip address

if no match is found it echos wrong, otherwise correct
[/quote]


bingo ;) not reading my posts :)
Link to comment
Share on other sites

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.