源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php 验证码实例代码

  • 时间:2022-05-27 13:28 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php 验证码实例代码
如果要用php的画图函数,首先要启用这个模块的功能。就是把php.ini中php_gd2.dll前面的注释去掉就好了。   下面开始画图:
[u]复制代码[/u] 代码如下:
  <?php session_start(); //生成验证码图片 Header("Content-type: image/PNG"); $im = imagecreate(44,18); // 画一张指定宽高的图片 $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色 imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中 $vcodes = ""; 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); } $_SESSION['VCODE'] = $vcodes; 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); ?>
  基本就是这样实现了,其实如果给图片打水印也无非就是往图片里面写字,原理都差不多的。   使用的地方直接   <img src="xxx.php" /> 填写这个php文件的名字,就可以使用了。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部