首页 › 日存档 › 2010年01月28日

简洁PHP验证码程序:session生成图片

正 文:

昨天捣鼓了一下PHP验证码并生成图片程序,采用了session识别,稍微改进了一下目前网络上流传的PHP验证码,加入杂点,数字颜色随机显示,控制4位数字显示;话不多说了,程序如下,分享出来。????效果图如下:

PHP验证码程序:session生成图片

新建yz.php验证码生成文件:????注意:以下代码需要打开php的GD库,修改php.in文件的配置,把已经注释掉的行之前的分号取消即可:extension=php_gd2.dll。

<?
session_start();
//生成验证码图片
Header(“Content-type:?image/PNG”);
$im?=?imagecreate(44,18);
$back?=?ImageColorAllocate($im,?245,245,245);
imagefill($im,0,0,$back);?//背景srand((double)microtime()*1000000);
//生成4位数字
for($i=0;$i<4;$i++){
$font?=?ImageColorAllocate($im,?rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im,?5,?2+$i*10,?1,?$authnum,?$font);
}for($i=0;$i<100;$i++)?//加入干扰象素
{
$randcolor?=?ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im,?rand()%70?,?rand()%30?,?$randcolor);
}
ImagePNG($im);
ImageDestroy($im);$_SESSION['VCODE']?=?$vcodes;
?> 继续阅读 »

解決浏览器兼容性-CSS hack:区分IE6,IE7,firefox

区别不同浏览器,CSS hack写法:

区别IE6FF
background:orange;
*background:blue;

区别IE6IE7
background:green !important;
background:blue;

区别IE7FF
background:orange;
*background:green;

区别FFIE7IE6
background:orange;
*background:green !important;
*background:blue;

注:IE都能识别*;标准浏览器(如FF)不能识别*;
IE6能识别*,但不能识别 !important,
IE7能识别*,也能识别!important;
FF不能识别*,但能识别!important;
IE6 IE7 FF
* ×
!important ×

继续阅读 »