Jump to content

captchas & htaccess


ruthiepoos

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.