ruthiepoos Posted April 7, 2008 Share Posted April 7, 2008 Hi. I'm doing something wrong and I've been staring at this for so long, im just running in circles and im getting highly irritated -___- I am generating a random captcha with php for comments on a simple news system. The image is generated, and I can download and view it through FTP, so I know that it's being generated, I just cant get it to show up when it is accessed through a browser, all it shows is the alt text. I'll post what i have anyway. the .htaccess file - RewriteEngine On RewriteRule ^ver.jpg$ img.php creating the captcha - <?php session_start(); include("config.php"); $circles = rand(0, 5); //make some random circles $width = '100'; //the width $height = '25'; //the height you want $font = rand(8, 11); //random font size $string = $_GET['text']; //the text to add to the image $fontwidth = ImageFontWidth($font) * strlen($string); //font width $fontheight = ImageFontHeight($font); //font height $im = @imagecreate($width, $height); //create the image $background_color = imagecolorallocate($im, 255, 255, 255); //the background color $text_color = imagecolorallocate($im, rand(0, 100), rand(0, 100), rand(0, 100)); //text color, randomness for ($i = 1; $i <= $circles; $i++) { //loop for circles $randomcolor = imagecolorallocate($im, rand(100, 255), rand(100, 255), rand(100, 255)); //create the circles imagefilledellipse($im, rand(0, $width - 10), rand(0, $height - 3), rand(20, 70), rand(20, 70), $randomcolor); //fill elipse with same color } //end the loop imagerectangle($im, 0, 0, $width - 1, $height - 1, $text_color); //create the rectangle shape for the image imagestring($im, $font, rand(3, $width - $fontwidth - 3), rand(2, $height - $fontheight - 3), $string, $text_color); //add the text header("Content-type: image/jpeg"); //creat the haeder of JPG imagejpeg($im, 'ver', 80); //create the image and shown if displayed somewhere on the server ?> and then the snippet where the captcha is needed in the news system - if (!$_POST['addcomment']) { //if forms not submitted $_SESSION['XXX_SEC_CODE_SEC_XXX'] =Codes(6); //generate a new security code print "<div> <h1>Add Comment to $arraynews[title]</h1> <p> <form method="post" action="news.php?x=addcomment&id=$id"> <fieldset style="border:0px solid #000000;"> <b>Your Name</b>: <input type="text" name="name" size="15" /> <b>Content</b>: <textarea rows="5" cols="25" name="msg"></textarea> <b>Image Verification</b>: *Enter the following backwards* <img src="ver.jpg?text=$_SESSION[XXX_SEC_CODE_SEC_XXX]" alt="Verification Image" /> <input type="text" size="15" name="verif" /> <input type="submit" name="addcomment" value="Post Comment" /> </fieldset> </form> </p> </div>"; Thanks for any help in advance Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/ Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 Im no expert with mod rewriting, but that doesn't look right to me. Try: RewriteEngine On RewriteRule ^ver.jpg([A-Za-z0-9?]+)$ img.php$1 Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511088 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 nope that actually stops the image being generated (oddly)... Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511090 Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 Found an easier way: RewriteEngine On RewriteRule ^ver.jpg$ img.php [QSA] Not sure why you're rewriting, but that should do it. Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511104 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 doesnt work either. I don't get it.... without the info in the htaccess file, nothing is created in the directory... with the info in htaccess it gets generated, but won't display... Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511108 Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 What happens if you browse directly to img.php with the relevant query string attached? Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511114 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 then it just prints out the URL... doesnt give you a 404 or anything o_O? the same as if you go to ver.jpg directly Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511116 Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 What do you mean by 'it just prints out the url'? Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511117 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 instead of showing the jpg in the browser, it just prints out into the browser window the url of where the image is so when you access img.php with the string in the url, it shows /new/img.php?text=ztPKij Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511120 Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 Hmm. I think the problem is that you're saving the image. You dont want to be doing that - you want to output the image directly. After all, its going to change all the time. Try changing this line: imagejpeg($im, 'ver', 80); //create the image and shown if displayed somewhere on the server To: imagejpeg($im, NULL, 80); //create the image and shown if displayed somewhere on the server And see where that gets you. Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511125 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 nothing... nothing gets stored in the directory now Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511127 Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 Nothing should be stored in the directory - you dont want anything stored do you? This image should be generated for the captcha, then discarded. However, you should now be able to browse directly to the image file and see it in your browser. Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511146 Share on other sites More sharing options...
ruthiepoos Posted April 7, 2008 Author Share Posted April 7, 2008 i see, i misunderstood that. argggh! still nothing... I do however receive a 404 now Link to comment https://forums.phpfreaks.com/topic/99952-captchas-htaccess/#findComment-511152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.