目标: 使用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. delphi 数据导出到word

    procedure TFrmWeekAnalysisQry.BtnExportToExcelClick(Sender: TObject);var wordApp,WordDoc,WrdSelectio ...

  2. QT数据库使用案列【联系人】-- 使用sqlite和QStringListModel

    [关于如何打包自己开发的程序为安装包,可以参考http://www.cnblogs.com/yuliyang/p/4242179.html] [简要功能介绍] 使用sqlite数据库和Qt搭建界面,实 ...

  3. 点亮一个led

    1:RS232电平:计算机串口 高电平为-12v,低电平为+12v,所以计算机与单片机进行通信的时候需要加电平转换芯片max232(高电平为-9到-12,低电平为+3到+12之间的. max232通常 ...

  4. Solaris10下Telnet、SSH、ftp使用root登录

    学习solaris过程中,使用SecureCRT.putty等工具用root账号登录,总是登录不上去,后来经老师解答和网上找答案,发现是 solaris默认是不可以远程使用root账号登录的,如果想开 ...

  5. git ssh key for github

    第一:检查.ssh是否存在(ls -al ~/.ssh) $ ls -al ~/.ssh Lists the files in your .ssh directory, if they exist 第 ...

  6. HW6.17

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. HW6.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  8. [学姿势]使用AngularJS+CodeIgniter框架经验谈

    这篇文章作为总结总结7月份参与项目时遇到的新东西和问题,包括这两个框架(CodeIgniter.AngularJS)以及两个功能实现.有前端调试显示动态认证,也有用php实现功能模块. 1.添加设备 ...

  9. 字符流缓冲区的使用之BufferedWriter和BufferedReader

    从字符输入流中读取文本,缓冲各个字符,从而实现字符.数组和行的高效读取,代码中使用了输入缓冲区的特有的方法:readLine(),获取一行文本数据 import java.io.BufferedRea ...

  10. 集合框架-Map练习-记录字母出现的次数

    /* * 练习: * 字符串"abcb453   sddbs343bsjvAJBBDVBs21768723",获取该字符串中,每一个字母出现的次数. * 要求打印结果是:a(2)b ...