实现图形验证码

要求如下:
1.程序文件名为img_code_1.php
2.此程序接受一个参数来动态生成验证码的数字(注意不是随机数)。
3.调用格式为img_code_1.php?img_code=12345。
4.生成的图形验证码的大小为120*30。
5.生成的图形验证码的字体大小为5,位置为10与8。
6.图片背景色为RGB(0,0,0),字体颜色为RGB(255,255,255)。

分析:img_code_1.php?img_code=12345
是一个携带img_code参数的get请求,开头要用一个$_GET[‘img_code’]来获取。这就是php简单便捷的优势,要什么直接拿什么。

 
	$image_code = $_GET['img_code'];
	header("Content-type:image/png"); //以图形方式执行
	$image = imagecreate(120, 30); //创建图片120*30。
	$blank = imagecolorallocate($image,0,0,0);//图片背景色为RGB(0,0,0),
	$white = imagecolorallocate($image, 255, 255, 255);//字体颜色为RGB(255,255,255)
	imagefill($image,0,0,$white); //填充背景色
	imagestring($image, 5, 10, 8, $image_code, $blank);//生成的图形验证码的字体大小为5,位置为10与8。
	imagepng($image);
	imagedestroy($image);//销毁图片,释放资源
 ?>

你可能感兴趣的:(服务器端程序设计,php)