Jump to content


Photo

valadating random number


  • Please log in to reply
20 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 08:28 AM


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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 08:38 AM

<?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>


#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 08:44 AM

try it our self with the ! there i dont see nothink try.


if the number matches the crack should echo correct else not correct.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 08:50 AM

<?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>

you didnt name the submit button

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 08:55 AM

gooing mad lol hair falling out dam thing .


wont work plase anyone try the code cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 08:57 AM

the code i posted works, i tried it

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 09:00 AM

if you enter the number dosent echo success try sorry.

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 09:01 AM

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 (!$_POST['submit']) { ... }

and

<input type="submit" value="send" name='submit'>


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 09:02 AM

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

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 09:03 AM

lol yeah that too. your generated code needs to be put inside a if(!$_POST['submit']) { ... }
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 09:04 AM

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>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 09:06 AM

change it to this:
<?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>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 09:07 AM

can it be solved with using sessions i wonder.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 09:08 AM

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

#15 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 09:11 AM

can it be solved with using sessions i wonder.


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

#16 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 09:12 AM

okay revised 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>


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 09:12 AM

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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 09:16 AM

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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#19 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 01 July 2006 - 09:28 AM

can it be solved with using sessions i wonder.


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



bingo ;) not reading my posts :)

#20 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 01 July 2006 - 09:32 AM

Here is a link for generating an image code and using sessions http://www.evolt.org...ms_random_image

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users