redarrow Posted July 1, 2006 Share Posted July 1, 2006 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> Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/ Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51588 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 try it our self with the ! there i dont see nothink try.if the number matches the crack should echo correct else not correct. Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51590 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51593 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 gooing mad lol hair falling out dam thing .wont work plase anyone try the code cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51596 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 the code i posted works, i tried it Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51597 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 if you enter the number dosent echo success try sorry. Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51599 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 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 buttonif ([color=red]![/color]$_POST['submit']) { ... }and <input type="submit" value="send" [color=red]name='submit'[/color]> Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51600 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51601 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 lol yeah that too. your generated code needs to be put inside a if(!$_POST['submit']) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51602 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 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> Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51603 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 change it to this:[code]<?phpif($_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] Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51605 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 can it be solved with using sessions i wonder. Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51607 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 I will explain the method you are doing:1. you generate the code2. you submit a code3. a new code is generated4. 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 Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51609 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 [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 addressif no match is found it echos wrong, otherwise correct Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51610 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 okay revised code:[code]<?phpif($_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] Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51611 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51612 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 Crayon Violent the code you posted is so good but becouse the value matches the echo success is always lolbrain teaser man lol............there is a way to get a generated number to match via a form on one page but how sessions maybedont no but does exist promise Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51613 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 [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 addressif no match is found it echos wrong, otherwise correct[/quote]bingo ;) not reading my posts :) Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51614 Share on other sites More sharing options...
tomfmason Posted July 1, 2006 Share Posted July 1, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51615 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Author Share Posted July 1, 2006 Thank you so much this will stop all the hart ake of users using a database method well done cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13366-valadating-random-number/#findComment-51623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.