Without GD support, things will be slightly more complicated but certainly not impossible. The following is a realistic strategy you can implement to create captcha images without GD support: 1. Create captcha in your local computer using your favorite photo editor. You can even make it very challenging as long as it is still readable at your desired image size. 2. Upload all the images to your FTP server specifying a clear path such as: /captchapath/1.bmp 3. Make a MYSQL table called "captcha" containing three fields:
Suppose you have 20 captcha images saved to your server. You should have a PHP script that will generate a random number from 1 to 20, and then fetch the image path corresponding to that number in the MySQL database. Typically you can have a script like this: <?php //connect database $username = "xxx"; $password = "xxx"; $hostname = "xxx"; $database = "xxx"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //select a database to work with $selected = mysql_select_db($database,$dbhandle) or die("Could not select $database"); echo 'Valid Email <br />'; echo '<input type="text" name="rty" size="50">'; echo '<br /><br />'; echo 'Enter captcha (Case sensitive for security measure) <br />'; echo '<input type="text" name="cvd" size="50">'; echo '<br /><br />'; //generate captcha $random= rand(1,12); $random = mysql_real_escape_string(stripslashes($random)); $result2 = mysql_query("SELECT `imagepath` FROM `captcha` WHERE `number`='$random'") or die(mysql_error()); $row = mysql_fetch_array($result2) or die("Invalid query: " . mysql_error()); $captcha = $row['imagepath']; echo '<img src="'.$captcha.'"/>'; echo '<br /><br /><input type="submit" /></form>'; $random = mysql_real_escape_string(stripslashes($random)); //extract answer of captcha $result3 = mysql_query("SELECT `answer` FROM `captcha` WHERE `number`='$random'") or die(mysql_error()); $row = mysql_fetch_array($result3) or die("Invalid query: " . mysql_error()); $answer = $row['answer']; //store answer to a session variable $_SESSION['captchaanswer']=$answer; ?> That concludes this tutorial. I hope you found it helpful.
blog comments powered by Disqus |
|
|
|
|
|
|
|