【PHP】原生验证码

版权声明:咔咔 来自https://blog.csdn.net/fangkang7 https://blog.csdn.net/fangkang7/article/details/88692512

author:咔咔

wechat:fangkangfk、

/**
     * author:咔咔
     *
     * 验证码
     */
    public function codeAction() {

        Header("Content-type: image/PNG");

        $rand ="";

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

            $rand.=dechex(rand(0,15));

        }

        $im = imagecreate(100,30);

        $gray = ImageColorAllocate($im, 200,200,200);

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

            $te=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));

        }
        imagefill($im,0,0,$gray);

        while(($rand=rand()%100000)<10000);

        $_SESSION['rand']=$rand;

        imagestring($im, 5, 30, 10, $rand, $te);


        for($i=0;$i<200;$i++)
        {
            $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));

            imagesetpixel($im, rand()%100 , rand()%50 , $randcolor);
        }

        imageline($im,0,rand(0,100),100,rand(0,15),$randcolor);

        imageline($im,0,rand(0,100),100,rand(0,15),$randcolor);

        imageline($im,0,rand(0,100),100,rand(0,15),$randcolor);

        ImagePNG($im);

        ImageDestroy($im);

    }

猜你喜欢

转载自blog.csdn.net/fangkang7/article/details/88692512