<?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. ES集群爆红,有未分配的片

    curl GET http://192.168.46.166:9200/_cluster/health?level=indices curl -XPUT '192.168.46.166:9200/_c ...

  2. 2017.5.16 comparator和comparable的比较及使用

    参考来自: http://blog.csdn.net/lifuxiangcaohui/article/details/41543347 http://www.cnblogs.com/liuyuanyu ...

  3. Linux Java开发环境

    一.旧版本JDK卸载 1.卸载系统自带JDK版本 #rpm -qa|grep gcj 查看到如下信息,如图所示:   进行卸载默认安装JDK: #rpm -e --nodeps java-1.4.2- ...

  4. 扩充STL-编写自己的迭代器

    这里的迭代器能够与STL组件共同工作,是对STL的一种扩充.   自定义迭代器必须提供iterator_traits的五种特性,分别是迭代器类型.元素类型.距离类型.指针类型与reference类型. ...

  5. Jmeter启动报注册表警告

    启动Jmeter后,控制台出现如下的警告: 主要出现的原因是: java.util.prefs.WindowsPreferences需要保存信息到HKEY_LOCAL_MACHINE\Software ...

  6. 自动化统一安装部署tomcat

    背景:多台服务器来回切换,安装部署tomcat,浪费时间 目的: 一次修改,统一安装,统一部署. 进程:ps -ef|grep tomcat|grep -v 'grep'|awk '{print $2 ...

  7. pomodoro源码

    有网友问我要pomodoro源码.事实上这个程序非常easy,仅仅是定时器,定时弹出置顶窗体.用c++builder6.0写.放一个TPopupMenu 右键菜单,一个TTrayIcon 一个托盘图标 ...

  8. C#实现发送手机短信

  9. Ubuntu16.04 打开txt文件乱码

    最近遇到个小问题:Ubuntu16.04下打开txt出现乱码,倒腾下解决了这个问题,记录下来. Ubuntu16.04 默认已经安装gedit.直接双击被打开的文件默认用gedit打开,显然这种方式行 ...

  10. Lua学习十----------Lua数组

    © 版权声明:本文为博主原创文章,转载请注明出处 1.LUA数组 - 一维数组 - 多维数组 2.array.lua -- 一维数组 print("一维数组") array1 = ...