复制代码代码如下所示:
功能_code($ _code_length = 4美元= 75美元,_width,_height = 25){
为($我= 0;美元美元美元我<< _code_length;i++){
_nmsg美元= dechex(mt_rand(0));
}
_session美元{代码= _nmsg美元;

_img美元=新建一个真彩色图像(_width美元,美元_height);

_white美元= imagecolorallocate(_img美元,250, 250, 250);

imagefill(_img美元,0, 0美元,_white);

_gray美元= imagecolorallocate(_img美元,196, 196, 196);

Imagerectangle(_img美元,0, 0美元美元,_width-1,_height-1,_gray美元);

($ i = 0;$ i < 6;$ + +){
_md_color = imagecolorallocate美元(美元_img,mt_rand(200255),mt_rand(200255),mt_rand(200255));
imageline(_img美元,mt_rand(0,_width美元(0美元),mt_rand,_height),mt_rand(0,_width美元(0美元),mt_rand,_height),_md_color美元);
}

($ i = 0;$ i < 50;$ + +){
_md_color = imagecolorallocate美元(美元_img,mt_rand(200255),mt_rand(200255),mt_rand(200255));
imagestring(_img美元,1,mt_rand(1,_width-5美元(1美元),mt_rand,_height-5),×
}

为($我= 0;美元美元美元我<< _code_length;i++){
_md_color = imagecolorallocate美元(美元_img,mt_rand(0102),mt_rand(0102),mt_rand(0102));
imagestring(_img美元,5美元,我_width美元/美元_code_length + mt_rand(1, 10),mt_rand(1,_height美元/ 2美元),_session {代码} {我},_md_color美元);
}

页眉(内容类型:图像);

imagepng($ _img);

销毁一图像($ _img);
}