<?php
session_start();
// Settings: You can customize the captcha here
$image_width = 120;
$image_height = 40;
$characters_on_image = 4;
$font = 'c:/windows/fonts/arial.ttf';

// The characters that can be used in the CAPTCHA code.
// avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyzABCDEFGHJKMNPQRSTWXYZ';
$random_dots = 10;
$random_lines = 30;
$captcha_text_color = "0x142864";
$captcha_noice_color = "0x142864";

$code = '';

$i = 0;
while ($i < $characters_on_image) {
    $code .= substr($possible_letters, mt_rand(0, strlen($possible_letters) - 1), 1);
    $i ++;
}

$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);

/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'], $arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], $arr_noice_color['green'], $arr_noice_color['blue']);

/* generating the dots randomly in background */
for ($i = 0; $i < $random_dots; $i ++) {
    imagefilledellipse($image, mt_rand(0, $image_width), mt_rand(0, $image_height), 2, 3, $image_noise_color);
}

/* generating lines randomly in background of image */
for ($i = 0; $i < $random_lines; $i ++) {
    imageline($image, mt_rand(0, $image_width), mt_rand(0, $image_height), mt_rand(0, $image_width), mt_rand(0, $image_height), $image_noise_color);
}

/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code);
$x = ($image_width - $textbox[4]) / 2;
$y = ($image_height - $textbox[5]) / 2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code);

/* Show captcha image in the page html page */
header('Content-Type: image/jpeg'); // defining the image type to be shown in browser widow
imagejpeg($image); // showing the image
imagedestroy($image); // destroying the image instance
$_SESSION['code'] = strtoupper($code);

function hexrgb($hexstr)
{
    $int = hexdec($hexstr);

    return array(
        "red" => 0xFF & ($int >> 0x10),
        "green" => 0xFF & ($int >> 0x8),
        "blue" => 0xFF & $int
    );
}
?>

  

;

最简单的php验证码的更多相关文章

  1. 一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确

    一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确       最近没事研究了下验证码的的动态生成及通过cookie实现HTML页面对用户输入的验证码的校验,简要如下: 1.写 ...

  2. 基于Python使用SVM识别简单的字符验证码的完整代码开源分享

    关键字:Python,SVM,字符验证码,机器学习,验证码识别 1   概述 基于Python使用SVM识别简单的验证字符串的完整代码开源分享. 因为目前有了更厉害的新技术来解决这类问题了,但是本文作 ...

  3. 用Java制作一个简单的图片验证码

    //Java实现简单验证码功能 package project; import java.awt.Color; import java.awt.Font;import java.awt.Graphic ...

  4. python+selenium十三:破解简单的图形验证码

    此方法可破解简单的验证码,如: 注:中文识别正在寻找办法 安装: 1.python3 2.Pillow 3.pytesseract 4.tesseract-ocr    下载地址:https://pa ...

  5. 用javascript编写一个简单的随机验证码程序

    简单模拟网页的随机数字验证码,效果图如下: html代码: <div id="content"> <div class="left"> ...

  6. 简单的js验证码

    转自:未找到 <script type ="text/javascript" language ="javascript">     var cod ...

  7. ios 简单的倒计时验证码数秒过程实现

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) ...

  8. 生成简单的php验证码

    之前发表过,但是上面只是一个截图,不便于大家复制和使用,所以在这重新发表一遍. <?php //生成验证码图片 Header("Content-type: image/JPEG&quo ...

  9. django 利用pillow 进行简单的设置验证码(python)

    1.导入模块 并定义一个验证状态 from PIL import Image, ImageDraw, ImageFont from django.utils.six import BytesIO de ...

  10. Java 简单的登录验证码

    1 验证码的作用 验证码是为了区分人与机器,如果没有验证码机制,web网站或者应用会遇到很多问题,具体如下: ① 网站容易被暴力登录攻破密码,可以制作一个自动程序不断的尝试登录,密码很容易被破解,系统 ...

随机推荐

  1. Yum编译安装Error Downloading Packages报错

    1:执行yum clean all 清除缓存目录下的软件包及旧的headers: 2:接着执行 yum list重新列出所有已经安装和可以安装的软件包: 3:重新执行上述命令,发现yum编译成功: 注 ...

  2. ansible自动化工具使用

    1.服务端配置 安装即可,无需启动,在安装ansible之前需要配置epel源 [root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirr ...

  3. Ubuntu 查看网关地址方法

    Ubuntu 查看网关地址方法 2017年01月10日 09:03:02 阅读数:3527 1. ip route show 2.route -n or netstat -rn 3.tracerout ...

  4. 转:Spring mvc中@RequestMapping 6个基本用法小结

    Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58)   阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...

  5. hdu 1030 Delta-wave(数学题+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1030 Delta-wave Time Limit: 2000/1000 MS (Java/Others ...

  6. mysql left join查询没走索引

    SELECT t0.ID as id, t0.`NAME` as name, t0.PHONE as phone, t0.`CITY_CODE` as cityCode, t0.SHOOTING_TI ...

  7. django项目搭建

    参见https://www.imooc.com/video/13931 1.安装python,从官网python.org下载msi安装2.7,安装完后,输入python可以看到版本 2.djangop ...

  8. 关于汉诺塔,C++代码,代码效果演算

     1.故事介绍 汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具.大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上依照大小顺序摞着64片黄金圆盘.大梵天命令婆罗门把圆盘 ...

  9. 如何为Apache JMeter开发插件(一)

    本文转载于http://blog.csdn.net/column/details/12925.html,作者:xreztento 作者写的很精华,我打算在此系列操作一遍后,加多点截图,便于更多人更快上 ...

  10. 读EXCEL

    import xlrdbook=xlrd.open_workbook('app_student.xls')sheet=book.sheet_by_index(0)#根据(索引)顺序获取到sheet页# ...