Jump to content

Captcha not working...


dennismonsewicz

Recommended Posts

<?php
header( "Content-type: image/png" );
session_start();
function createImg() {
	$num_chars=6;//number of characters for captcha image
	$characters=array_merge(range(0,9),range('A','Z'),range('a','z'));//creating combination of numbers & alphabets
	shuffle($characters);//shuffling the characters	

	$captcha_text="";
	for($i=0;$i<$num_chars;$i++) {
		$captcha_text.=$characters[rand(0,count($characters)-1)];
	}

	$_SESSION['captcha'] =$captcha_text;// assigning the text into session

	$captcha_image=imagecreatetruecolor(140,30);

	$captcha_background=imagecolorallocate($captcha_image,225,238,221);//setting captcha background colour
	$captcha_text_colour=imagecolorallocate($captcha_image,58,94,47);//setting cpatcha text colour

	imagefilledrectangle($captcha_image,0,0,140,29,$captcha_background);//creating the rectangle

	imagettftext($captcha_image,20,0,11,21,$captcha_text_colour,$captcha_text);
	imagepng($captcha_image);
	imagedestroy($captcha_image);
}

echo '<img src="' . createImg() . '" alt="Captcha" />';

?>

 

The above just outputs weird characters the screen, such as:

�PNG  ��� IHDR����������qa!���gIDATh���A � ���1�y`� H�s4�SФc��p������`R�I&�`R�I&�`R�I&�`R�I&�`R�I&�`R�I&�`R�I&���l{\����IEND�B`�

 

Any ideas why this is happening?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/189784-captcha-not-working/
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.