php验证码
时间:2023-3-1 22:06 作者:wen 分类: PHP
php-->验证码
1.php.ini 配置
extension=php_gd2.dll
2.函数
imagecreate(width,height); 基于调试板,
imagecreatetruecolor(int $width,int $height); 基于真色彩,返回一个图形资源
imagegif / imagejpeg / imagepng 将图片以什么格式输出
注意:在做图的时候必须指定文件的头信息
header('content-type:image/gif');
imagedestroy(resource $image);销毁图像内存
imagecolorallocate(resource $image,int $red,int $green,int $blue); 预定义一个颜色/给图像分配颜色
bool imagechar(resource $image,int $font,int $x,int $y,string $c,int $color); 水平画一个字符
bool imagecharup(resource $image,int $font,int $x,int $y,string $c,int $color); 垂直的画一个字符
bool imagestring(resource $image,int $font,int $x,int $y,string $c,int $color); 水平的画一个字符串
array imagettftext(resource $image,float $fontSize,float $angle,int $x,int $y,int $color,$fontfile,string $text);
bool imagefilledrectangle(resource $image,int $x1,int $y1,int $x2,int $y2,int $color); 画一个矩形填充
bool imagesetpixel(resource $image,int $x,int $y,int $color); 画一个锚点
bool imageline(resource $image,int $x1,int $y1,int $x2,int $y2,int $color) 画一个干扰线
3.cookie 和 session
cookie 客户端会话,用来在客户端存储数据的数组
创建cookie
setcookie('下标名称','value','生命期');
调用
$_COOKIE['下标'];
session 服务器会话,
session_start();
创建
$_SESSION['index']=value;
调用
$_SESSION[]
面试:
session 和 cookie区别
cookie:
存储在客户端 , 在整个生命期限 有效
session
存在服务器端,消亡关闭浏览器/ session_destroy()方法
关闭cookie session还能用不
能用:
session_id();
cookie 和session 关系 sessionid相同的
<a href="b.php?sid=<?php echo session_id() ?>">b</a>
b页面上
session_id($_GET["sid"]); 同样可以得到 sessionid
4 验证码的使用:
verify.php--->在浏览器上输出了一个 图片
onclick 单机左键
<img src="verify.php" onclick="this.src='verify.php?math='+Math.random();">
this 这个元素 表示img this写在谁上面 ,表示的是谁
. 的
src 路径属性
5 图片等比缩放:
列表页面 图片 和 详细页面 图片 一样的,大小不一样 (宽度 高度 硬盘的容量 都不同)
bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y ,
int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
重采样拷贝部分图像并调整大小(等比缩放 缩小+方法)
resource imagecreatefromgif ( string $filename )
resource imagecreatefromjpeg ( string $filename )
resource imagecreatefrompng ( string $filename )
由文件或 URL 创建一个新图象(把图片载入到php程序中)
gd2
array getimagesize(strimg $filename) 取得图像大小
Array
(
[0] => 1920 宽度
[1] => 1080 高度
[2] => 2 图片类型gif=1 jpg=2 png=3
[3] => width="1920" height="1080"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
文件上传:
form enctype="multipart/form-data"
编码 大部分 表单 数据
用$_FILES接收
Array
(
[name] => 4.jpg 文件名称
[type] => image/jpeg mime类型
[tmp_name] => C:\Windows\temp\php3B4E.tmp c盘临时位置
[error] => 0 错误信息
[size] => 20880 文件大小
)
move_uploaded_file("临时位置",“指定位置”)
注意:在图片上传中,数据库中存储的是图片的路径, upload存储的是图片,路径和图片必须对应
显示在页面,只需要从数据库中读出路径就可以在页面显示了