| | |
image verification problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 4
Reputation:
Solved Threads: 0
index.php
formhandler.php
why does it give error?
http://img412.imageshack.us/img412/9467/ivxb3.gif
this tutorial is in http://www.phpnoise.com/tutorials/1/1
PHP Syntax (Toggle Plain Text)
<?php /*header*/ header("Content-Type: image/png"); /*We'll set this variable later.*/ $new_string; /*register the session variable. */ session_register('new_string'); /*You will need these two lines below.*/ echo "<html><head><title>Verification</title></head>"; echo "<body>"; /* set up image, the first number is the width and the second is the height*/ $im = imageCreate(200, 40); /*creates two variables to store color*/ $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); /*Runs the string through the md5 function*/ $string = md5(rand(0,9999)); /*creates the new string. */ $new_string = substr($string, 17, 5); /*fill image with black*/ imageFill($im, 0, 0, $black); /*writes string */ imageString($im, 4, 96, 19, $new_string, $white); /* output to browser*/ imagePNG($im, "verify.png"); imageDestroy($im); ?>
formhandler.php
PHP Syntax (Toggle Plain Text)
<?php /*This starts the session that we created on the last page*/ session_start(); /*This trims the random variable of any white space that the user may have unknowingly put in.*/ $random = trim($random); /*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.*/ /*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.*/ if ($new_string == $random){ echo "You are verified"; } else{ echo "Please go back and get verified."; } /*I plugged our image in like I would any other image.*/ echo "<img src=\"verify.png\">"; echo "<br><br>"; echo "Type the code you see in the image in the box below. (case sensitive)"; echo " <form action=\"formhandler.php\" method=post>"; echo "<input name=\"random\" type=\"text\" value=\"\">"; echo "<input type=\"submit\">"; echo "</form>"; echo "</body>"; echo "</html>"; ?>
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.
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
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
dezignwork.com
![]() |
Similar Threads
- Image Verification in Asp.net (ASP.NET)
- image verification (PHP)
- Dreamweaver Image Moving Problem (Site Layout and Usability)
- image retrieval problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: Want to learn PHP Options
- Next Thread: Is session will work if cookies are disbaled on clinet side?
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





