function _code($_width = 75,$_height = 25,$_rnd_code = 4,$_flag = false){
//创建随机码
for ($i=0;$i<$_rnd_code;$i++){
$_nmsg .= dechex(mt_rand(0, 15));
}
//保存在session
$_SESSION['code'] = $_nmsg;
//创建一张图像
$_img = imagecreatetruecolor($_width,$_height);
//白色
$_white = imagecolorallocate($_img,255,255,255);
//填充
imagefill($_img,0,0,$_white);
if ($_flag){
//黑色,边框
$_black = imagecolorallocate($_img,0,0,0);
imagerectangle($_img,0,0,$_width-1,$_height-1,$_black);
}
//随机画出六个线条
for ($i=0;$i<6;$i++){
$_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);
}
//随机雪花
for ($i=0;$i<100;$i++){
$_rnd_color = imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);
}
//输出验证码
for ($i=0;$i<strlen($_SESSION['code']);$i++){
$_rnd_color = imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));
imagestring($_img,5,$i*$_width/$_rnd_code+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$_rnd_color);
}
//输出图像
header('Content-Type:image/png');
imagepng($_img);
//销毁
imagedestroy($_img);
}
封装了
记得要在调用的页面开启 session_start();
PHP的Discuz!论坛架设方法,架设Discuz!论坛不但需要服务器支持PHP而且需要MYSQL数据库的支持。
PHP主机架设很复杂,这里就不介绍了,提供一个PHP环境包下载,
下到本地解压、启动就行了,简单一些。
Apache+PHP+MySQL+Nginx+Memcached+ASP一键环境包: http://www.nicenic.com/design/?s=lily
解压缩后把Discuz!文件夹改名为BBS复制到你所建的Web主目录(web)中,打开浏览器输入
http://您的IP/bbs/install.php就会出现Discuz!论坛的安装向导。
选择完全同意,然后出现选择数据库的选项。
轻松用建站宝盒架设自己的论坛网站
http://www.nicenic.com/design/?s=lily