<?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. 2017.7.1 nginx反向代理服务器域名解析配置(已验证可使用)

    下载地址:http://learning.happymmall.com/ 前提:ftpserver已经开启,并且设置为: 1.获得安装文件 2.修改配置文件 2.1 修改conf/nginx.conf ...

  2. 12. 改变JDK编译版本【从零开始学Spring Boot】

    spring Boot在编译的时候,是有默认JDK版本的,如果我们期望使用我们要的JDK版本的话,那么要怎么配置呢? 这个只需要修改pom.xml文件的<build>-- <plug ...

  3. LoadRunner调用md5方法

    LoadRunner调用md5方法 上一篇 / 下一篇  2011-04-29 11:25:12 / 个人分类:Loadrunner 查看( 958 ) / 评论( 0 ) / 评分( 0 / 0 ) ...

  4. openstack-计算节点安装(Node)

    感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限.错误之处在所难免,欢迎指正. 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  5. 为什么 Linux 的 htop 命令完胜 top 命令

    在 Linux 系统中,top 命令用来显示系统中正在运行的进程的实时状态,它显示了一些非常有用的信息,比如 CPU 利用情况.内存消耗情况,以及每个进程情况等.但是,你知道吗?还有另外一个命令行工具 ...

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

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

  7. IIS相关知识和经验的碎皮化记录

    1.IIS(Internet Information Services)网站本机可以访问,局域网其他机器无法访问 导致这个问题之一是防火墙规则,解决办法如下: 1)[开始]打开[控制面板],选择[WI ...

  8. linux下 apache启动、停止、重启命令

    假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况 apahce启动命令:推荐/usr/local/apache2/bin/apachectl start apa ...

  9. 莫小安 CentOS7使用firewalld打开关闭防火墙与端口

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  10. 在Ubuntu 16.04下安装 virtualbox 5.2

        sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" ...