Location: PHPKode > projects > Free Forum System(Tech Book) > Tech-Book-Free Forum-www.webdevelopplus.com/securityimage.php
<?php
	
	session_start();
		
	if (isset($_GET["no"]))
		$no = (int) $_GET["no"]; // get no of characters for security string
	else
		$no = 5; // by default value is 6
		
	if ($no <= 0 || $no > 16) // value of no must be between 1 and 16
		$no = 5;
		
	
	$secString = "";
	
		
	$mString = array("0","1","2","3","4","5","6","7","8","9"); // array to generate the security string


	$mKeys = array_rand($mString, $no); // generate random string of width $na
	
	foreach($mKeys as $n){
		$secString .= $mString[$n];
	}
	
	
	setcookie('secWord',$secString);
	$server = $_SERVER['SERVER_SOFTWARE'];
	$occurance = substr_count($server, 'Win32');
	
	
	$im = imagecreatetruecolor(240, 50); // Create the image
	
	if ($occurance) { // if server is Win32
		// Create some colors
		$white = imagecolorallocate($im, 255, 255, 255);
		$grey = imagecolorallocate($im, 0, 128, 128);
		$black = imagecolorallocate($im, 255, 0, 0);
		
		imagefilledrectangle($im, 0, 0, 399, 49, $white);
				
		// Replace path by your own font path
		$font = 'arial';  //use for for security image
		
		$angle = rand(-5,5);  // Angle between -5 to +5
		$size = 14 ; // size of the font
		
		// Add some shadow to the text
		imagettftext($im, $size, $angle, 11, 21, $grey, $font, $secString);

		// Add the text
		imagettftext($im, $size, $angle, 10, 20, $black, $font, $secString);
		
	} else { // if server is not Win32, Server is Unix or Linux
	
		// Create some colors
		$white = imagecolorallocate($im, 255, 255, 255);
		$text_color = imagecolorallocate($im, 255, 0, 0);
		
		imagefilledrectangle($im, 0, 0, 399, 49, $white);
		
		imagestring($im, 5, 5, 5,  $secString, $text_color);
	}
	
	// Using imagepng() results in clearer text compared with imagejpeg()
	header("Content-type: image/png"); // set the Header use png image for better results
	imagepng($im);
	imagedestroy($im);
	
?>
Return current item: Free Forum System(Tech Book)