944,035 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2114
  • PHP RSS
Jul 16th, 2007
0

image verification problem

Expand Post »
index.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. /*header*/
  3. header("Content-Type: image/png");
  4.  
  5. /*We'll set this variable later.*/
  6. $new_string;
  7.  
  8. /*register the session variable. */
  9. session_register('new_string');
  10.  
  11. /*You will need these two lines below.*/
  12. echo "<html><head><title>Verification</title></head>";
  13. echo "<body>";
  14.  
  15. /* set up image, the first number is the width and the second is the height*/
  16. $im = imageCreate(200, 40);
  17.  
  18. /*creates two variables to store color*/
  19. $white = imageColorAllocate($im, 255, 255, 255);
  20. $black = imageColorAllocate($im, 0, 0, 0);
  21.  
  22.  
  23.  
  24. /*Runs the string through the md5 function*/
  25. $string = md5(rand(0,9999));
  26.  
  27. /*creates the new string. */
  28. $new_string = substr($string, 17, 5);
  29.  
  30. /*fill image with black*/
  31. imageFill($im, 0, 0, $black);
  32.  
  33. /*writes string */
  34. imageString($im, 4, 96, 19, $new_string, $white);
  35.  
  36. /* output to browser*/
  37. imagePNG($im, "verify.png");
  38. imageDestroy($im);
  39.  
  40. ?>


formhandler.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. /*This starts the session that we created on the last page*/
  4. session_start();
  5.  
  6.  
  7. /*This trims the random variable of any white space that the user may have unknowingly put in.*/
  8. $random = trim($random);
  9.  
  10. /*Below is a conditional statement: In English it reads, if the string that the user put into the text box is equal to what is in the image then print to the screen, "You are verified." If they are not equal it tells the user to go back and try again.*/
  11.  
  12. /*We can use the variable $new_string because we registered it into our session on the last page, it retains its value that it had on the first page.*/
  13. if ($new_string == $random){
  14. echo "You are verified";
  15. }
  16. else{
  17. echo "Please go back and get verified.";
  18. }
  19.  
  20.  
  21. /*I plugged our image in like I would any other image.*/
  22. echo "<img src=\"verify.png\">";
  23. echo "<br><br>";
  24. echo "Type the code you see in the image in the box below. (case sensitive)";
  25. echo " <form action=\"formhandler.php\" method=post>";
  26. echo "<input name=\"random\" type=\"text\" value=\"\">";
  27. echo "<input type=\"submit\">";
  28. echo "</form>";
  29. echo "</body>";
  30. echo "</html>";
  31.  
  32. ?>

why does it give error?

http://img412.imageshack.us/img412/9467/ivxb3.gif

this tutorial is in http://www.phpnoise.com/tutorials/1/1
Last edited by zodehala; Jul 16th, 2007 at 12:03 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zodehala is offline Offline
8 posts
since Oct 2006
Jul 17th, 2007
0

Re: image verification problem

if you deal with the session initialization before you send headers to the browser then you shouldn't have this error.

If you want to use the following:
/*header*/
header("Content-Type: image/png");


then you could store this in image.php and then call it like:

<img src="image.php" border="0" />

I hope that helps.

tim
Reputation Points: 11
Solved Threads: 2
Newbie Poster
dezignwork is offline Offline
21 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Want to learn PHP Options
Next Thread in PHP Forum Timeline: Is session will work if cookies are disbaled on clinet side?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC