Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

valadating random number

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>

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
try it our self with the ! there i dont see nothink try.


if the number matches the crack should echo correct else not correct.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
gooing mad lol hair falling out dam thing .


wont work plase anyone try the code cheers.

Share this post


Link to post
Share on other sites
if you enter the number dosent echo success try sorry.

Share this post


Link to post
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]>

Share this post


Link to post
Share on other sites
thats because when you submit, a new code is generated, your constantly 1 step behind. thats why u need a fixed code, otherwise your going to be guessing for years

Share this post


Link to post
Share on other sites
lol yeah that too. your generated code needs to be put inside a if(!$_POST['submit']) { ... }

Share this post


Link to post
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>

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
i agree so why not help me holp the last code genrated in a sssion will that do it.


that was funny lol..........................

everone you post wont work lol its a brain killer lol. sorry

Share this post


Link to post
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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
Here is a link for generating an image code and using sessions [url=http://www.evolt.org/securing_forms_random_image]http://www.evolt.org/securing_forms_random_image[/url]

Share this post


Link to post
Share on other sites
Thank you so much this will stop all the hart ake of users using a database method well done cheers.

Share this post


Link to post
Share on other sites

×

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.