php 验证码2

<?php

/**

* 图片验证码生成

* @copyright (c) Emlog All Rights Reserved

*/

session_start();

$randCode = '';

$chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPRSTUVWXYZ23456789';

for ( $i = 0; $i < 5; $i++ ){

$randCode .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);

}

$_SESSION['chkcode'] = strtolower($randCode);

$img = imagecreate(70,22);

$bgColor = isset($_GET['mode']) && $_GET['mode'] == 't' ? imagecolorallocate($img,245,245,245) : imagecolorallocate($img,255,255,255);

$pixColor = imagecolorallocate($img,mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));

for($i = 0; $i < 5; $i++){

$x = $i * 13 + mt_rand(0, 4) - 2;

$y = mt_rand(0, 3);

$text_color = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));

imagechar($img, 5, $x + 5, $y + 3, $randCode[$i], $text_color);

}

for($j = 0; $j < 60; $j++){

$x = mt_rand(0,70);

$y = mt_rand(0,22);

imagesetpixel($img,$x,$y,$pixColor);

}

header('Content-Type: image/png');

imagepng($img);

imagedestroy($img);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,789评论 0 33
  • <?php /** * 图片验证码生成 * @copyright (c) Emlog All Rights Res...
    过往_eed8阅读 166评论 0 0
  • 背景 验证码就是把一串随机产品的数字动态生成一幅图片,再加上干扰元素。此时用户可以通过肉眼能识别里面的数字或者字符...
    dy2903阅读 2,163评论 0 7
  • 兴许是春天来到 就连凋零也长成茂盛 想问你要一个关于爱的承诺 把万水千山都喜欢一遍 最后你在我的航程上 你在我的视线里
    胡珂Garfield阅读 179评论 0 0
  • 偷偷的看着你,看着你的背影,看着你头也不回一路走下去,这样多好呀! 无意间,在车里听到这首歌,庄心妍的《一直想...
    尐先生Zz阅读 218评论 0 0