image verification problem

Reply

Join Date: Oct 2006
Posts: 4
Reputation: zodehala is an unknown quantity at this point 
Solved Threads: 0
zodehala zodehala is offline Offline
Newbie Poster

image verification problem

 
0
  #1
Jul 16th, 2007
index.php

  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

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 21
Reputation: dezignwork is an unknown quantity at this point 
Solved Threads: 2
dezignwork's Avatar
dezignwork dezignwork is offline Offline
Newbie Poster

Re: image verification problem

 
0
  #2
Jul 17th, 2007
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
hosting :: development :: design
dezignwork.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC