验证码

本文介绍了一个简单的PHP脚本,用于生成包含四位随机数字的验证码图片。该脚本使用了session管理,并通过设置HTTP头来确保正确的内容类型和字符集。图片的背景颜色、边框颜色以及文字颜色均为随机生成,增加了验证码的安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php
/**
 * Created by PhpStorm.
 * User: dllo
 * Date: 16/8/12
 * Time: 下午3:14
 */
session_start();
header("Content-type:text/html;charset=utf-8");
header("Content-type: image/png");
$width = 200;
$height = 100;
$im = @imagecreatetruecolor($width,$height) or die('创建图像失败');
$backgroundColor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagefill($im,0,0,$backgroundColor);
$borderColor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagerectangle($im,0,0,$width-1,$height-1,$borderColor);
$textColor = imagecolorallocate($im,rand(50,180),rand(50,180),rand(50,180));
$fontSize = rand(14,18);
$code =  rand(999,9999);
imagestring($im,$fontSize,rand(20,$width/2),rand($height /2 ,$height-20),$code,$textColor);
$_SESSION["mycode"] = $code;
imagepng($im);
imagedestroy();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值