Index: /temp/trunk/html/test/uehara/captcha/ajax_captcha/create_image.php
===================================================================
--- /temp/trunk/html/test/uehara/captcha/ajax_captcha/create_image.php	(revision 10447)
+++ /temp/trunk/html/test/uehara/captcha/ajax_captcha/create_image.php	(revision 10447)
@@ -0,0 +1,66 @@
+<?
+/*
+	This is PHP file that generates CAPTCHA image for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
+
+	You may use this code in your own projects as long as this 
+	copyright is left in place.  All code is provided AS-IS.
+	This code is distributed in the hope that it will be useful,
+ 	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+	
+	For the rest of the code visit http://www.WebCheatSheet.com
+	
+	Copyright 2006 WebCheatSheet.com	
+
+*/
+
+//Start the session so we can store what the security code actually is
+session_start();
+
+//Send a generated image to the browser 
+create_image(); 
+exit(); 
+
+function create_image() 
+{ 
+    //Let's generate a totally random string using md5 
+    $md5_hash = md5(rand(0,999)); 
+    //We don't need a 32 character long string so we trim it down to 5 
+    $security_code = substr($md5_hash, 15, 5); 
+
+    //Set the session to store the security code
+    $_SESSION["security_code"] = $security_code;
+
+    //Set the image width and height 
+    $width = 100; 
+    $height = 20;  
+
+    //Create the image resource 
+    $image = ImageCreate($width, $height);  
+
+    //We are making three colors, white, black and gray 
+    $white = ImageColorAllocate($image, 255, 255, 255); 
+    $black = ImageColorAllocate($image, 0, 0, 0); 
+    $grey = ImageColorAllocate($image, 204, 204, 204); 
+
+    //Make the background black 
+    ImageFill($image, 0, 0, $black); 
+
+    //Add randomly generated string in white to the image
+    ImageString($image, 3, 30, 3, $security_code, $white); 
+
+    //Throw in some lines to make it a little bit harder for any bots to break 
+    ImageRectangle($image,0,0,$width-1,$height-1,$grey); 
+    imageline($image, 0, $height/2, $width, $height/2, $grey); 
+    imageline($image, $width/2, 0, $width/2, $height, $grey); 
+ 
+    //Tell the browser what kind of file is come in 
+    header("Content-Type: image/jpeg"); 
+
+    //Output the newly created image in jpeg format 
+    ImageJpeg($image); 
+    
+    //Free up resources
+    ImageDestroy($image); 
+} 
+?>
Index: /temp/trunk/html/test/uehara/captcha/ajax_captcha/ajax_captcha.js
===================================================================
--- /temp/trunk/html/test/uehara/captcha/ajax_captcha/ajax_captcha.js	(revision 10447)
+++ /temp/trunk/html/test/uehara/captcha/ajax_captcha/ajax_captcha.js	(revision 10447)
@@ -0,0 +1,69 @@
+/*
+	This is the JavaScript file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
+
+	You may use this code in your own projects as long as this 
+	copyright is left in place.  All code is provided AS-IS.
+	This code is distributed in the hope that it will be useful,
+ 	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+	
+	For the rest of the code visit http://www.WebCheatSheet.com
+	
+	Copyright 2006 WebCheatSheet.com	
+
+*/
+//Gets the browser specific XmlHttpRequest Object 
+function getXmlHttpRequestObject() {
+ if (window.XMLHttpRequest) {
+    return new XMLHttpRequest(); //Mozilla, Safari ...
+ } else if (window.ActiveXObject) {
+    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
+ } else {
+    //Display our error message
+    alert("Your browser doesn't support the XmlHttpRequest object.");
+ }
+}
+
+//Our XmlHttpRequest object
+var receiveReq = getXmlHttpRequestObject();
+
+//Initiate the AJAX request
+function makeRequest(url, param) {
+//If our readystate is either not started or finished, initiate a new request
+ if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
+   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
+   receiveReq.open("POST", url, true);
+   //Set the function that will be called when the XmlHttpRequest objects state changes
+   receiveReq.onreadystatechange = updatePage; 
+
+   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+   receiveReq.setRequestHeader("Content-length", param.length);
+   receiveReq.setRequestHeader("Connection", "close");
+
+   //Make the request
+   receiveReq.send(param);
+ }   
+}
+
+//Called every time our XmlHttpRequest objects state changes
+function updatePage() {
+ //Check if our response is ready
+ if (receiveReq.readyState == 4) {
+   //Set the content of the DIV element with the response text
+   document.getElementById('result').innerHTML = receiveReq.responseText;
+   //Get a reference to CAPTCHA image
+   img = document.getElementById('imgCaptcha'); 
+   //Change the image
+   img.src = 'create_image.php?' + Math.random();
+ }
+}
+
+//Called every time when form is perfomed
+function getParam(theForm) {
+ //Set the URL
+ var url = 'captcha.php';
+ //Set up the parameters of our AJAX call
+ var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
+ //Call the function that initiate the AJAX request
+ makeRequest(url, postStr);
+}
Index: /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha.php
===================================================================
--- /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha.php	(revision 10447)
+++ /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha.php	(revision 10447)
@@ -0,0 +1,31 @@
+<?
+/*
+	This is the back-end PHP file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
+	
+	You may use this code in your own projects as long as this 
+	copyright is left in place.  All code is provided AS-IS.
+	This code is distributed in the hope that it will be useful,
+ 	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+	
+	For the rest of the code visit http://www.WebCheatSheet.com
+	
+	Copyright 2006 WebCheatSheet.com	
+*/
+
+//Continue the session
+session_start();
+
+//Make sure that the input come from a posted form. Otherwise quit immediately
+if ($_SERVER["REQUEST_METHOD"] <> "POST") 
+ die("You can only reach this page by posting from the html form");
+
+//Check if the securidy code and the session value are not blank 
+//and if the input text matches the stored text
+if ( ($_REQUEST["txtCaptcha"] == $_SESSION["security_code"]) && 
+    (!empty($_REQUEST["txtCaptcha"]) && !empty($_SESSION["security_code"])) ) {
+  echo "<h1>Test successful!</h1>";
+} else {
+  echo "<h1>Test failed! Try again!</h1>";
+}
+?>
Index: /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha_test.htm
===================================================================
--- /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha_test.htm	(revision 10447)
+++ /temp/trunk/html/test/uehara/captcha/ajax_captcha/captcha_test.htm	(revision 10447)
@@ -0,0 +1,47 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<!--
+	This is the HTML front-end of the How to Create CAPTCHA Protection using PHP and AJAX Tutorial.
+	
+	You may use this code in your own projects as long as this 
+	copyright is left in place.  All code is provided AS-IS.
+	This code is distributed in the hope that it will be useful,
+ 	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+	
+	For the rest of the code visit http://www.WebCheatSheet.com
+	
+	Copyright 2006 WebCheatsheet.com	
+-->
+
+<html>
+	<head>
+		<script language="JavaScript" type="text/javascript" src="ajax_captcha.js"></script>
+	</head>
+	<body>
+	<form id="frmCaptcha" name="frmCaptcha">
+		<table> 
+			<tr>
+				<td align="left">
+					<label for="captcha">Captcha</label>
+				</td>
+				<td>
+					<input id="txtCaptcha" type="text" name="txtCaptcha" value="" maxlength="10" size="32" />
+				</td>
+				<td> 
+					<img id="imgCaptcha" src="create_image.php" />
+				</td>
+			</tr>
+			<tr>
+				<td>&nbsp;</td>
+				<td>
+					<input id="btnCaptcha" type="button" value="Captcha Test" name="btnCaptcha" 
+						onclick="getParam(document.frmCaptcha)" />
+				</td>
+			</tr>
+		</table> 
+
+		<div id="result">&nbsp;</div>
+	</form>
+	</body>
+</html>
