/core/captcha.php
PHP | 41 lines | 28 code | 7 blank | 6 comment | 6 complexity | dec58a56c8aeb8e358a2b8cb070b96f6 MD5 | raw file
- <?php
- /**
- * ???????
- * @copyright (c) Emlog All Rights Reserved
- * @version emlog-3.5.0
- * $Id: checkcode.php 1698 2010-05-03 03:57:40Z emloog@gmail.com $
- */
- if(!defined('RQ_ROOT')) exit('Access Denied');
- doAction('captcha_create_myself');
- session_start();
- $randCode = '';
- $chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPRSTUVWXYZ23456789';
- for ( $i = 0; $i < 4; $i++ ){
- $randCode .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
- $_SESSION['code'] = strtoupper($randCode);
- $img = imagecreate(55,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 < 4; $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 < 50; $j++){
- $x = mt_rand(0,55);
- $y = mt_rand(0,22);
- imagesetpixel($img,$x,$y,$pixColor);
- }
- header('Content-Type: image/png');
- imagepng($img);
- imagedestroy($img);
- exit();