收藏一个比较美观的PHP验证码类_PHP教程

WBOY
Release: 2016-07-13 10:33:02
Original
1084 people have browsed it

验证码的用途就不用多说了,之前也写了一篇关于PHP验证码的文章,但是没有封装成类。下面就介绍一个PHP的一个验证码类。

codes = implode('',array_slice($codeArray,0,4));
        }
		
        public function CreateImg()
        {
            $_SESSION['check_pic'] = $this->codes;
            $img = imagecreate(70,25);
            imagecolorallocate($img,222,222,222);
            $testcolor1 = imagecolorallocate($img,255,0,0);
            $testcolor2 = imagecolorallocate($img,51,51,51);
            $testcolor3 = imagecolorallocate($img,0,0,255);
            $testcolor4 = imagecolorallocate($img,255,0,255);
			
            for ($i = 0; $i < 4; $i++)
            {
                imagestring($img,rand(5,6),8 + $i * 15,rand(2,8),$this->codes[$i],rand(1,4));
            }
            imagegif($img);
        }
    }
	
    $code = new SecurityCode();
    $code->CreateImg();
	
	$code = NULL;
?>
Copy after login

封装成类之后,加入了构造函数,使用起来也方便些。你也可以继续完善下这个验证码类,比如加入析构函数,如何更节省内存等等。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/752568.htmlTechArticle验证码的用途就不用多说了,之前也写了一篇关于PHP验证码的文章,但是没有封装成类。下面就介绍一个PHP的一个验证码类。 ?php session_s...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!