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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.