zoukankan      html  css  js  c++  java
  • php随机验证码

    今天同学问我,用php怎么写验证码,由于是新手所以花了半天的时间才完成。而且功能很是简单呵呵。今天本来打算写session和cookie的看来是要明天了。

     1 <?php
     2      $image_width=140;
     3      $image_height=50;
     4      srand(microtime()*10000);
     5      for($i=0;$i<4;$i++){
     6               $number.=dechex(rand(0,15));
     7             }
     8     $check=$number;
     9     $im=imagecreate($image_width,$image_height);
    10     imagecolorallocate($im,255,255,255);
    11     for($i=0;$i<strlen($check);$i++){
    12         $font=rand(40,80);
    13         $x=rand(1,8)+$image_width*$i/4;
    14         $y=rand(1,$image_height/4);
    15         $color=imagecolorallocate($im,rand(0,100),rand(0,150),rand(0,200));
    16         imagestring($im,$font,$x,$y,$check[$i],$color);
    17         }
    18         imagepng($im);
    19 
    20         imagedestroy($im);
    21 ?>

    这些代码已经测试过了,没有问题。如果万一到了首页,呵呵。希望大大们给点意见和更加好的方法,轻喷。

  • 相关阅读:
    小伙子的毕业设计
    mongoDB
    Java面试题笔试题收集
    react-router4 介绍
    React 组件间通信 总结
    react ajax
    react应用(基于react脚手架)
    React 之 组件生命周期
    组件收集表单数据
    组件的组合使用
  • 原文地址:https://www.cnblogs.com/legendyang/p/3302192.html
Copyright © 2011-2022 走看看