php创建最简单验证码
2017-01-20 17:03
477 查看
php创建最简单验证码
<?php $char = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'; $char_len = strlen($char); $code=''; for($i = 1; $i <= 4; $i++){ $code_index = mt_rand(0, $char_len - 1); $code = $code.''.$char[$code_index]; } session_start(); $_SESSION['captcha_code'] = $code; $img_path = 'captcha_bg'.mt_rand(1, 5).'.jpg'; $img = imagecreatefromjpeg($img_path); $font = 5; $size_width = imagesx($img); $size_height = imagesy($img); $font_width = imagefontwidth($font); $font_height = imagefontheight($font); $color = mt_rand(1,2) == 1 ? imagecolorallocate($img, 0, 0, 0) : imagecolorallocate($img, 0xff, 0xff, 0xff); imagestring($img, $font, ($size_width-$font_width*4)/2, ($size_height-$font_height)/2, $code, $color); header('Content-Type:image/jpeg;'); imageJPEG($img); imageDestroy();
相关文章推荐
- php笔记之GD库图片创建/简单验证码
- php创建简单验证码
- php笔记之GD库图片创建/简单验证码
- php笔记之GD库图片创建/简单验证码
- 使用zeng studio 创建的php调用webservice soap简单实例
- (二)基于PHP——简单的WSDL的创建(WSDL篇)
- PHP生成验证码的简单代码示例
- php中DOMDocument简单用法(XML创建、添加、删除、修改)
- php 一个简单的图像创建程序
- 一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之创建输出验证码图片的控制器
- 分享一个php验证码程序 简单 实用
- 用php写了个简单的验证码破解程序
- 【php】php验证码的简单实现
- 简单PHP留言板之一 —— MYSQL的设计与创建
- 一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之创建输出验证码图片的控制器
- php中DOMDocument简单用法(XML创建、添加、删除、修改)
- 分享一个php验证码程序 简单 实用
- php 简单创建图像
- php中DOMDocument简单用法示例代码(XML创建、添加、删除、修改)
- 一个简单的php图形验证码生成程序