zoukankan      html  css  js  c++  java
  • php 产生验证码

    <?php 
    session_start();
    header("Content-type:image/png");
    srand((double)microtime()*1000000);
    $imagewidth=160;
    $imageheight=40;
    $image=imagecreate($imagewidth,$imageheight);
    $background_color=imagecolorallocate($image,200,200,200); //gray
    $white = imagecolorallocate($image, 255, 255, 255);
    $black=imagecolorallocate($image,0,0,0);
    $red = imagecolorallocate($image, 255, 0, 0);
    $font = 'arial.ttf';

    //随机生成一些干扰的像素
    for($i=0;$i<400;$i++)
    {
    $randcolor=imagecolorallocate($image,rand(10,255),rand(10,255),rand(10,255));
    imagesetpixel($image,rand()%$imagewidth,rand()%$imageheight,$randcolor );

    }
    //随机的画几条线段
    for($i=0;$i<6;$i++)
    {
    imageline($image,rand()%$imagewidth,rand()%$imageheight,rand()%$imagewidth,rand()%$imageheight,$black);
    }

    //生成验证字符串
    $array="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $authcode=''; //不写这行有错误,unexpected );expected ;
    for($i=0;$i<4;$i++)
    {
    $authcode.=substr($array,rand(0,67),1);
    }

    //imagettftext($image,2,0,0,0,$red,'arial ttf',$authcode); //显示不出图片啊,不知道什么原因。
    //imagettftext($image, 20, 0, 10, 20, $red,$font,$authcode); 还是错

    imagestring($image,5,40,15,$authcode,$red); //font 是 1,2,3,4 或 5
    imagepng($image);
    imagedestroy($image);
    $_SESSION['authcode']=$authcode;

    ?>


  • 相关阅读:
    消息路由的构成
    消息的构造
    消息传递通道
    消息传递系统
    EXtJS Ext.data.Model
    oracle coherence介绍及使用
    LINUX下安装和配置WEBLOGIC10.0.3
    WebLogic中"域"的概念
    WebLogic中的一些基本概念
    下属有能力却不服管,你该怎么办?
  • 原文地址:https://www.cnblogs.com/youxin/p/2390701.html
Copyright © 2011-2022 走看看