Page 1 of 1

Verify script.

Posted: Wed May 31, 2006 7:25 am
by SpArKs
Strange.

If no code is entered you get the error message...ok, fine. If random numbers are entered it some how bypasses the error message.

This is bugging me...


Dir:
module/GuestBook/index.php:

Form that displays the head.php number/image(code) with a text field for that code

Code: Select all

<form method="post" action="/modules/GuestBookVerify/index.php">
<?php $die=rand(1,10000); ?>
<img src="modules/GuestBook/head.php?text=<?php echo($die); ?>" /><br />
Please enter the number in the above picture<br> 
<input name="code" type="text" /><br />
<input type="hidden" name="coder" value="<?php echo($die); ?>">
  <input type="submit" value="Verify" />
</form>

Dir:
module/GuestBook/head.php:
Generates the code/image

Code: Select all

<?php
header ("Content-type: image/png");
$string=$_GET['text'];
$img_handle = ImageCreate (45, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($img_handle, 345, 23, 6);
ImageString ($img_handle, 31, 5, 5, $string, $txt_color);
ImagePng ($img_handle);
?>

Dir:
module/GuestBookVerify/index.php:
Requests and verifies code, if correct displays "HIDDEN DATA" else "WRONG CODE ERROR MESSAGE"... well, supposed too...

Code: Select all

<?php
  $code = $_REQUEST['coder'];
  $inp = $_REQUEST['code'];
 if ($code=$inp) /*<- see below*/
{ 
echo("  HIDDEN DATA   ");
}
else
{
echo("  WRONG CODE ERROR MESSAGE  ");
}
?>
I tried swapping things about, no avail. Even tried having two "=", no good. Also tried swapping the "=" for a "->", it gave me a "WRONG CODE ERROR MESSAGE" no matter what...

As you can see, with a ratio of 1 to 100, my php skills rate closely around the mark of 1...

Any clues?...I must be close...

I will provide a link to an example if requested.

Posted: Wed May 31, 2006 7:59 am
by bmcewan
In your if statement, you should have == and not =. == is a comparison, and = will assign.

Try adding

Code: Select all

print_r($_POST);
to the top of your page module/GuestBookVerify/index.php: to see if your hidden var coder has a value submitted with the form

Code: Select all

<?php 
  print_r($_POST);
  $code = $_REQUEST['coder']; 
  $inp = $_REQUEST['code']; 
 if ($code == $inp) /*<- == is a comparison*/ 
{ 
echo '  HIDDEN DATA   '; 
} 
else 
{ 
echo '  WRONG CODE ERROR MESSAGE  '; 
} 
?>

Posted: Wed May 31, 2006 8:20 am
by SpArKs
BINGO!

Thanks man.

I did have the script as ($code==$inp) at one point... what I did between then and now... god knows!


This script was a free form to mail script, but I nailed it down to just the verify part. So anyone can use/hack/whatever it.

Thanks again!