Rheves Posted July 18, 2007 Share Posted July 18, 2007 I've attached the CAPTCHA script I'm using, and it's one I'm trying to use on two websites. It works fine on one, but on the other the code isn't getting passed into $_SESSION['security_code']. The code is exactly the same on both sites so I imagine this must be a server-side problem. Does anyone know how I would go about making the second website's CAPTCHA work properly? <?php session_start(); session_register('security_code'); /* * File: CaptchaSecurityImages.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 03/08/06 * Updated: 07/02/07 * Requirements: PHP 4/5 with GD and FreeType libraries * Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '23456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $width = isset($_GET['width']) ? $_GET['width'] : '120'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6'; $captcha = new CaptchaSecurityImages($width,$height,$characters); ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 Remove the session_register part. www.php.net/session_register it has been replaced with $_SESSION['index'] Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 18, 2007 Author Share Posted July 18, 2007 I've removed the session register part, and it still doesn't work. When you say it's been replaced by $_SESSION['index'] do you mean I should swap out $_SESSION['security_code'] = $code; for $_SESSION['index'] = $code;? If so I went ahead and tried that and it also didn't work. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 I've removed the session register part, and it still doesn't work. When you say it's been replaced by $_SESSION['index'] do you mean I should swap out $_SESSION['security_code'] = $code; for $_SESSION['index'] = $code;? If so I went ahead and tried that and it also didn't work. Now the index was just a representation. The ['index'] part is the index of the array. Which means look in the session array for an index of 'index' and print out that value. Where is the page you are using Captcha on, do you have session_start() on that page also? Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 18, 2007 Author Share Posted July 18, 2007 http://www.readingmadeez.com/Contact2.php is the test page it's on, and session_start() is declared at the top. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 Just out of curiosity, does the image actually display? If so it seems that the settings for the session are different, maybe the session on the new site is being handled via url instead of cookies. I do not know, but it is a server issue, and I meant by posting the code, not to post the actual page but the code that defines the page. It may be something in there too. Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 18, 2007 Author Share Posted July 18, 2007 Yep, the image displays fine, initially it didn't and I had to get the server guys to enable gd support though. Here's the Contact2 page: <?php $Sent = ""; $Type = "comment"; if(isset($_GET['type'])){ $Type = $_GET['type']; } if(isset($_GET['message'])){ $Sent = $_GET['message']; } include_once("./top.php"); ?> <font size="+1"><b>Contact Us</b></font> <?php if($Sent == "sent"){ echo"<br><br><b><u>Your message was sent successfully!</u></b><br><br>"; } ?> <p><b>Premier Assistive Technology</b><br> <b>Executive Offices<br> 1309 N. William St.<br> Joliet, IL 60435<br> Phone:</b> 815-927-7390<br> <b>Fax:</b> 815-722-8802<br> <b>General Inquiries:</b> <a href="mailto:info@readingmadeeasy.com">info@readingmadeeasy.com</a><br> <b>Technical Support:</b> <A href="mailto:Tech@readingmadeeasy.com">Tech@readingmadeeasy.com</a><br> <b>Webmaster:</b> <a href="mailto:Bryan@readingmadeez.com">Bryan@readingmadeez.com</a></p> <P>If you want to contact us you can use the information above or use one of the options below:<br><br> <?php if($Type != "comment"){ echo"If you want to send us a Comment: <a href=\"./Contact2.php?type=comment\">Click here to send a comment</a>.<br>"; } if($Type != "question"){ echo"If you want to ask a Question: <a href=\"./Contact2.php?type=question\">Click here to ask a question</a>.<br>"; } if($Type != "problem"){ echo"If you have a Technical Problem: <a href=\"./Contact2.php?type=problem\">Click here to get help with a technical problem</a>."; } ?> </p> <?php if($Type == "comment"){ echo"<font size=\"+1\"><b>Comment Form</b></font><br> <form METHOD=\"POST\" Action=\"./ProcessContact2.php?Type=comment\"> <table summary =\"Comment table\"> <tr><td>Name:</td><td><input type=\"text\" name=\"name\"></td></tr> <tr><td>Company:</td><td><input type=\"text\" name=\"company\"></td></tr> <tr><td>Email:</td><td><input type=\"text\" name=\"email\"></td></tr> <tr><td>Product:</td><td><select name=\"product\"><option value=\"No Product In Particular\">No product in particular</option>"; $query = "SELECT * FROM ProductSearch"; $result = mssql_query($query); while($row = mssql_fetch_array($result)){ $Product = $row["Name"]; echo"<option value=\"$Product\">$Product</option>"; } echo"</select></td></tr> <tr><td>Phone:</td><td><input type=\"text\" name=\"phone\"></td></tr> <tr><td>Operating System:</td><td><select name=\"OS\"><option value=\"Windows XP PRO\">Windows XP Pro</option><option value=\"Windows XP HOME\">Windows XP Home</option><option value=\"Windows 2000\">Windows 2000</option><option value=\"Windows ME\">Windows ME</option><option value=\"Windows 98 Se\">Windows 98 Se</option></select></td></tr> <tr><td>Version:<br>(Enter 0 if you do not know)</td><td><input type=\"text\" name=\"version\" value=\"0\"></td></tr> <tr><td>Verification Number:<br><img src=\"CaptchaSecurityImages.php\" /></td><td><input id=\"security_code\" name=\"security_code\" type=\"text\" /></td></tr> <tr><td>Comment:</td><td><textarea rows=\"8\" cols=\"60\" name=\"message\"></textarea></td></tr></table> <input type=\"submit\" value=\"Submit\"></form>"; } if($Type == "question"){ echo"<font size=\"+1\"><b>Question Form</b></font><br> <form METHOD=\"POST\" Action=\"./ProcessContact.php?Type=question\"> <table summary=\"Question table\"> <tr><td>Name:</td><td><input type=\"text\" name=\"name\"></td></tr> <tr><td>Company:</td><td><input type=\"text\" name=\"company\"></td></tr> <tr><td>Email:</td><td><input type=\"text\" name=\"email\"></td></tr> <tr><td>Product:</td><td><select name=\"product\"><option value=\"No Product In Particular\">No product in particular</option>"; $query = "SELECT * FROM ProductSearch"; $result = mssql_query($query); while($row = mssql_fetch_array($result)){ $Product = $row["Name"]; echo"<option value=\"$Product\">$Product</option>"; } echo"</select></td></tr> <tr><td>Phone:</td><td><input type=\"text\" name=\"phone\"></td></tr> <tr><td>Operating System:</td><td><select name=\"OS\"><option value=\"Windows XP PRO\">Windows XP Pro</option><option value=\"Windows XP HOME\">Windows XP Home</option><option value=\"Windows 2000\">Windows 2000</option><option value=\"Windows ME\">Windows ME</option><option value=\"Windows 98 Se\">Windows 98 Se</option></select></td></tr> <tr><td>Version:<br>(Enter 0 if you do not know)</td><td><input type=\"text\" name=\"version\" value=\"0\"></td></tr> <tr><td>Verification Number:<br><img src=\"CaptchaSecurityImages.php\" /></td><td><input id=\"security_code\" name=\"security_code\" type=\"text\" /></td></tr> <tr><td>Question:</td><td><textarea rows=\"8\" cols=\"60\" name=\"message\"></textarea></td></tr></table> <input type=\"submit\" value=\"Submit\"></form>"; } if($Type == "problem"){ echo"<font size=\"+1\"><b>Technical Problem Form</b></font><br> <form METHOD=\"POST\" Action=\"./ProcessContact.php?Type=problem\"> <table summary=\"Problem table\"> <tr><td>Name:</td><td><input type=\"text\" name=\"name\"></td></tr> <tr><td>Company:</td><td><input type=\"text\" name=\"company\"></td></tr> <tr><td>Email:</td><td><input type=\"text\" name=\"email\"></td></tr> <tr><td>Product:</td><td><select name=\"product\"><option value=\"No Product In Particular\">No product in particular</option>"; $query = "SELECT * FROM ProductSearch"; $result = mssql_query($query); while($row = mssql_fetch_array($result)){ $Product = $row["Name"]; echo"<option value=\"$Product\">$Product</option>"; } echo"</select></td></tr> <tr><td>Phone:</td><td><input type=\"text\" name=\"phone\"></td></tr> <tr><td>Operating System:</td><td><select name=\"OS\"><option value=\"Windows XP PRO\">Windows XP Pro</option><option value=\"Windows XP HOME\">Windows XP Home</option><option value=\"Windows 2000\">Windows 2000</option><option value=\"Windows ME\">Windows ME</option><option value=\"Windows 98 Se\">Windows 98 Se</option></select></td></tr> <tr><td>Version:<br>(Enter 0 if you do not know)</td><td><input type=\"text\" name=\"version\" value=\"0\"></td></tr> <tr><td>Verification Number:<br><img src=\"CaptchaSecurityImages.php\" /></td><td><input id=\"security_code\" name=\"security_code\" type=\"text\" /></td></tr> <tr><td>Problem:</td><td><textarea rows=\"8\" cols=\"60\" name=\"message\"></textarea></td></tr></table> <input type=\"submit\" value=\"Submit\"></form>"; } include_once("./bottom.php"); ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 In Contact2.php I do not see the session_start, is it in the top.php? Also let's see the code where the security image is actually being checked, IE ProcessContact2.php Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 18, 2007 Author Share Posted July 18, 2007 Yeah, session_start() is in top.php <?php include_once("./dbinfo.php"); $Type = ""; $Name = ""; $Company = ""; $Email = ""; $Product = ""; $Phone = ""; $OS = ""; $Version = ""; $Message = ""; $Verification = ""; $VerficiationGiven = ""; $Valid = "Yes"; if(isset($_GET['Type'])){ $Type = $_GET['Type']; } if(isset($_POST['name'])){ $Name = $_POST['name']; } if(isset($_POST['company'])){ $Company = $_POST['company']; } if(isset($_POST['email'])){ $Email = $_POST['email']; } if(isset($_POST['product'])){ $Product = $_POST['product']; } if(isset($_POST['phone'])){ $Phone = $_POST['phone']; } if(isset($_POST['OS'])){ $OS = $_POST['OS']; } if(isset($_POST['version'])){ $Version = $_POST['version']; } if(isset($_SESSION['index'])){//The correct verification number in the image $Verification = $_SESSION['index']; } if(isset($_POST['security_code'])){//The given verification for the image $VerificationGiven = $_POST['security_code']; } if(isset($_POST['message'])){ $Message = $_POST['message']; } $Name = str_replace("\'","`",$Name); $Email = str_replace("\'","`",$Email); $Phone = str_replace("\'","`",$Phone); $Company = str_replace("\'","`",$Company); $Version = str_replace("\'","`",$Version); $Message = str_replace("\'","`",$Message); $Name = str_replace("\\\"","`",$Name); $Email = str_replace("\\\"","`",$Email); $Phone = str_replace("\\\"","`",$Phone); $Company = str_replace("\\\"","`",$Company); $Version = str_replace("\\\"","`",$Version); $Message = str_replace("\\\"","`",$Message); $Error = ""; if($Version ==""){ $Valid = "Blank"; $Error1 = "Blank"; } if($Verification == $VerificationGiven) { $Valid = "Yes"; unset($_SESSION['security_code']); }else{ $Valid ="WrongNum"; $Error2 = "WrongNum"; } if($Valid == "Yes"){ $RecipientEmail = "Bryan@readingmadeeasy.ca"; if($Type == "comment"){ $Intro = "Comment From Customer"; } if($Type == "question"){ $Intro = "A customer has asked a question"; $RecipientEmail = "Bryan@readingmadeeasy.ca";} if($Type == "problem"){ $Intro = "A customer needs help with a problem"; } $MessageToSend = "Name: $Name\nCompany: $Company\nEmail: $Email\nPhone Number: $Phone\nProduct: $Product\nOperating System: $OS\nVersion: $Version\nMessage: $Message"; $headers = 'From: info@ReadingMadeEasy.com' . "\r\n" . 'Reply-To: info@ReadingMadeEasy.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //mail($RecipientEmail,$Intro,$MessageToSend,$headers); echo"$Verification :: $VerificationGiven :: $Valid"; if($Type == "question" || $Type == "problem"){ //header("Location: ./FAQ.php"); }else{ //header("Location: ./Contact.php?message=sent"); } }else{ include_once("./top.php"); if($Error1 == "Blank"){ echo"You have not entered a valid version, please go back and enter 0 if you do not know what version you have.<br><br>"; } if($Error2 =="WrongNum"){ echo"You have entered the wrong verification code, please go back and enter the code as you see it in the image.<br> $Verification :: $VerificationGiven :: $Valid";//Just for temporary testing } include_once("./bottom.php"); } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 if(isset($_SESSION['index'])){//The correct verification number in the image $Verification = $_SESSION['index']; Change that back to the security code. Read my reply #3. As for why its not working, it must be a server issue the code, other than noted above looks fine. Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 18, 2007 Author Share Posted July 18, 2007 Heh, I hadn't changed it back since I knew the old way wasn't working either. I'll request that the same settings that are on the working server be placed on the other server, since the same company is hosting both. Quote Link to comment Share on other sites More sharing options...
Rheves Posted July 24, 2007 Author Share Posted July 24, 2007 *Bump* The server admin won't clone over the same settings that are on the working server, so does anyone know the exact changes that need to be made? I've had him enable register_globals but I'm not sure what else to request be changed. From the phpinfo() this is what's under the session heading: session Session Support enabled Registered save handlers files user Registered serializer handlers php php_binary wddx This server is using PHP Version 5.2.1. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.