学习:PHP简单实例、验证码生成

PHP简单实例

匹配字符格式

‘\’为转义字符

‘\w’匹配任意一个数字、字母、或下划线,等价于【0-9a-zA-Z】

‘+’匹配1次或多次其前的原子

‘\d’为匹配任意一个十进制数字。等价于【0-9】

 

 

PHP生成验证码

1、背景设置:imagefill($image,0,0, $color1)

生成图片大小:

$image=imagecreatetruecolor(x_size,y_size)

设置背景颜色 :int col表示要填充的颜色

$color1=imagecolorallocate(int image,255,255,255);

2、验证码设置:

imagestring($image,$fontsize,$x,$y,$code,$color2);

设置字体大小:$fontsize

设置字体颜色:$color2=imagecolorallocate($image,rand() , rand(), rand());(1-120为深颜色)

设置变量生成随机验证码:$code=””;$code.=rand(0,9);

设置坐标:$x,$y

3、添加像素干扰

雪花点:

imagesetpixel($image, rand(), rand(), $color3);

设置点的颜色:$color3= imagecolorallocate($image,rand() , rand(), rand());(50-200颜色较浅)

线:

imageline($image,rand()rand(),rand(),rand(),$color4);

$color4= imagecolorallocate($image,rand() , rand(), rand());

4、生成验证码

header(“content-type:image/png”);//通知浏览器这不是文本而是图像

imagepng($img);生成png格式的图片输出给浏览器

imagedestroy($img);销毁图像资源,释放画布占用的内存空间

 

注:学习笔记 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值