目标: 使用php生成验证码

成品:

    

逻辑代码: authcode.php

<?php
header("Content-type:image/png");
session_start();
//$str用于存放验证码
$str="";
//$charset中剔除了0,o,1,l等易混淆字符
$cs="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345678923456789";
$img=imagecreate($width=100,$height=26);
//图片背景色使用浅色调
$img_bg=imagecolorallocate($img,rand(186,255), rand(186,255), rand(186,255));
for($i=0;$i<4;++$i){
    //文字颜色使用深色调
    $txt_color=imagecolorallocate($img,rand(0,86),rand(0,86),rand(0,86));
    //从$charset中随机出来一个字符
    $tmp=substr($cs,rand(0,strlen($cs)-1),1);
    //进行偏移和显示
    imagestring($img,5,$i*24+rand(6,15),rand(2,12),$tmp,$txt_color);
    $str.=$tmp;
}
//将验证码值放入session中以备后用(验证用户输入的验证码)
$_SESSION["authcode"]=$str;
//添加背景线条
for($j=0;$j<5;++$j){
    $line_color=imagecolorallocate($img,rand(150,210), rand(150,210), rand(150,210));
    imageline($img, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $line_color);
}
//添加噪点
for($i=0;$i<250;++$i){
    $img_noisy=imagecolorallocate($img,rand(150,210), rand(150,210), rand(150,210));
    imagesetpixel($img,rand(0,$width),rand(0,$height),$img_noisy);
}
imagepng($img);
imagedestroy($img);

前端使用: register.html

<img src="authcode.php"/>

php验证码制作的更多相关文章

  1. webform 图片验证码制作

    界面:1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.as ...

  2. MVC-简单验证码制作

    1.制作验证码: using System; using System.Collections.Generic; using System.Drawing; using System.Drawing. ...

  3. webform:图片水印、验证码制作

    一.图片水印 1:引命名空间System.Drawing; 前端代码 <div> <asp:FileUpload ID="FileUpload1" runat=& ...

  4. Java实现验证码制作之一Kaptcha验证码

    Kaptcha验证码 是google提供的验证码插件,使用起来相对简单,设置的干扰线以及字体扭曲不易让其他人读取破解. 这里我们需要 导入一个 kaptcha-2.3.jar  下载地址:http:/ ...

  5. Java实现验证码制作之一自己动手

    以前弄验证码都是现找现用,下面是自己跟着敲代码弄好的,记录一下,分享给大家. 我这里用的是Servlet ,Servlet代码如下 import java.awt.Color;import java. ...

  6. PHP实现验证码制作

    captcha.php(PHP产生验证码并储存Session): <?php //开启Session session_start(); //绘制底图 $image = imagecreatetr ...

  7. PHP - 验证码制作加验证

    一,主页 index.php   <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  8. PHP绘图案例讲解验证码制作

    <?php header("Content-type: image/png");//声明浏览器解析为图片 $width=200; $height=100; $color1=i ...

  9. Code笔记 之:注册页面验证码

    文章内容包括: 1.验证码制作 -- 中文|字母|数字|…… 2.图文验证码 -- 图片防盗链(PHP而非JS) 3.JS防止右键点击图片 4.input表单输入框不记录输入过的信息 5.CSS+di ...

随机推荐

  1. 【原】Storm及特点

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  2. 如何添加网站for Linux(绑定域名)

    [以下配置的路径以阿里云提供的标准环境路径为准,如果您另行安装,请根据实际安装路径配置].   1.cd /alidata/server/httpd/conf/vhosts/ 进入绑定域名所在目录, ...

  3. Good practice release jar to Nexus

    Step  suppose you need to develop a feature,when you finish the feature ,you need to release the jar ...

  4. leetcode@ [211] Add and Search Word - Data structure design

    https://leetcode.com/problems/add-and-search-word-data-structure-design/ 本题是在Trie树进行dfs+backtracking ...

  5. jexus asp.net Linux Web Server

    Jexus简介 Jexus web server for linux 是运行在Linux上的Web服务器.其安装和部署及其简单,直接支持Asp.net . 下载Jexus wget http://li ...

  6. Barcode記錄

    .net開源框架 Barcode Rendering Framework URL:http://barcoderender.codeplex.com/releases/view/91902 可產生BR ...

  7. Python解释器

    当我们编写Python代码时,我们得到的是一个包含Python代码的以.py为扩展名的文本文件.要运行代码,就需要Python解释器去执行.py文件. 由于整个Python语言从规范到解释器都是开源的 ...

  8. cocos2d-x 手势之简单实现

    转自:http://blog.sina.com.cn/s/blog_61ece099010187tl.html 手势之前也发过一篇,但是我感觉那个还不够轻巧. 而且大多数游戏里面不会有那么复杂的手势, ...

  9. 【转】SQL语句中的正则表达示

    正则表达式作用是匹配方本,将一个模式(正则表达式)与一个文本串进行比较. MySQL用WHERE子句对正则表达式提供了初步的支持,允许你指定用正则表达式过滤SELECT检索出的数据. MySQL仅支持 ...

  10. 成员方法与const之间的关系

    const可以放在成员方法的三个地方,前.中.后. 首先考虑在中间: 1.const修饰形参,表示形参是否为const 2.如果const修饰引用(指针指向的对象),可以进行过载,如果不是修饰引用(指 ...