验证码
验证码原理
Captcha:Completely Automated Public Turing Test to Tell Computers and Humans Apart (全自动区分计算机和人类的图灵测试)
验证码的意义:防止网站被别人恶意攻击
原理:人能够从图片中识别图片里面的内容,而电脑做不到。
验证码:将一系列随机产生的字符写入到对应的图片当中,然后将图片发送给浏览器,然后用户通过输入图片上的随机字符,最后发送给服务器进行比对。
2024年10月14日
Captcha:Completely Automated Public Turing Test to Tell Computers and Humans Apart (全自动区分计算机和人类的图灵测试)
验证码的意义:防止网站被别人恶意攻击
原理:人能够从图片中识别图片里面的内容,而电脑做不到。
验证码:将一系列随机产生的字符写入到对应的图片当中,然后将图片发送给浏览器,然后用户通过输入图片上的随机字符,最后发送给服务器进行比对。
2024年10月14日
本篇文章给大家带来的内容是关于php中图片处理和文件操作的方法小结(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
第一部分:图片处理
第一:图片缩放
图片等比例缩放、没处理透明色
代码如下:
function thumn($background, $width, $height, $newfile) {
list($s_w, $s_h)=getimagesize($background);//获取原图片高度、宽度
2024年10月14日
1. 创建与绘制图像
例:create_img.php
<?php
header("Content-type:image/gif");//向客户端发送原始的 HTTP 报头。Content-type:image/gif
$image = imagecreate(100,100);//创建100*100像素的画布资源
$blue = imagecolorallocate($image,0,0,255);//为$image画布设置图像颜色 蓝色
2024年10月14日
好久不写文章了,今天给大家带来php的高级功能实现技术,祝大家学业有成!
图像处理技术
基本图像处理技术
要想使用图片处理技术,必须先到php.ini中,开启“php_gd2.dll”库——通常称为GD库!
创建画布
画布 = ImageCreate(宽, 高); //普通低执行画布
2024年10月14日
现在自媒体泛滥,每个自媒体账号都会给自己的文章图片打上自己的水印,那么水印是怎么实现的呢?
今天就给大家看看水印的具体实现,话不多说,直接上代码:
<?php //告诉浏览器以jpeg图像的方式显示 header("Content-type:image/jpeg;charset=utf-8"); //创建画布 $width = 750; $height = 1334; //新建一个空白图像资源 $image = imagecreate($width, $height); //创建背景颜色 $white = imagecolorallocate($image, 255, 255, 255); //创建字体颜色 $red = imagecolorallocate($image, 255, 0, 0); //字符,转码 $font = mb_convert_encoding('segmentfault', "html-entities", "utf-8"); //开始绘画 imagettftext ($image, 50, 0, 200, 200, $red, 'msyh.ttc','segmentfault.com'); imagettftext ($image, 60, 0, 200, 300, $red, 'msyh.ttc',$font); //生成图像 imagejpeg($image,"3.jpg"); //目标图像 $dst_path = "3.jpg"; //水印图片 $src_path = 'sf.png'; //创建图片的实例 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //获取水印图片的宽高 list($src_w, $src_h) = getimagesize($src_path); //将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果,两个20是控制水印坐标位置 // imagecopymerge($dst, $src, 20, 20, 0, 0, $src_w, $src_h, 50); //如果水印图片本身带透明色,则使用imagecopy方法 imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h); //输出图片 list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path); switch ($dst_type) { case 1://GIF header('Content-Type: image/gif'); imagegif($dst); break; case 2://JPG header('Content-Type: image/jpeg'); imagejpeg($dst); break; case 3://PNG header('Content-Type: image/png'); imagepng($dst); break; default: break; } imagedestroy($dst); imagedestroy($src); $shuiyin = "gd.php"; //销毁资源 imagedestroy($image);
2024年10月14日
有些函数系统也帮忙打包好,以xxx.dll文件存放在ext、extras文件夹中,需要开启配置才能使用。这些函数称为扩展函数(extend)。
一、解决中文截取乱码mb_substr
echo mb_substr("中abc",0,2,"utf-8");
二、图片处理函数GD2
GD(graphic device,图形设备),负责在屏幕和打印机上输出信息。GD2是GDI的后续版本。要使用GD2,首先应该把网页打散作为图像(header),接着创建Graphics类对象(简单的来说,Graphics类对象就相当于画布,没画布我们在什么地方绘图呢?),然后调用一系列绘图方法即可,最后再生成图片、释放资源(destroy)。看下面的代码
2024年10月14日
PHP很强大可以轻松快捷的处理多种数据格式,在图像处理上也拥有强大而且简单的实现方式。
PHP处理图像需要拓展库GD库的支持
可以通过PHPINFO()函数查看GD库是否开启,如果没有开启在PHPINI中开启
检测拓展库是否加载:extension_loaded("GD")
2.PHP创建图片的方法
<?php
//1.发送HTTP头文件,声明内容为图像
2024年10月14日
这是一个专门练习文件上传的靶场,和sqli-labs靶场类似。
github项目地址:
https://github.com/c0ny1/upload-labs
2024年10月14日
首先我们分以下几个步骤:
1.使用php创建一个图像
2.登陆页面引入php创建的图像
3.验证输入的是否正确
这其中最核心的就是用php创建图像,那么接下来就跟着我一起开始吧
首先新建一个captcha.php 文件内容:
<?php
// 设置验证输出的内容,提示:一般剔除数字和字母容易混淆的几个
$data = "abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
// 创建一个画布,就是验证码的大小
$width = 100;
$height = 30;
$img = imagecreatetruecolor($width,$height);
$color = imagecolorallocate($img,0xcc,0xcc,0xcc);
// 填充颜色 imgefill()
imagefill($img,0,0,$color);
// 绘制画布的噪点 这里假设设置600个噪点
for($i=0;$i<600;$i++)
{
$color = imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100));
$x = rand(0,$width);
$y = rand(0,$height);
imagesetpixel($img,$x,$y,$color);
}
// 绘制画布的干扰线,这里假设画6道线
for($i = 0; $i<6; $i++)
{
$color = imagecolorallocate($img, rand(100, 200), rand(100, 200), rand(100,200));
$x1 = rand(0, $width);
$y1 = rand(0, $height);
$x2 = rand(0, $width);
$y2 = rand(0, $height);
imageline ($img, $x1, $y1, $x2, $y2, $color);
}
// 绘制圆来干扰 假设画4个圆
for ($i=0; $i<4; $i++)
{
$color = imagecolorallocate ($img, rand(100, 255), rand(100, 255), rand(100,255));
imageellipse ($img, rand(0, $width), rand(0, $height),30,30,$color);
}
/**
* 验证码内容
* $len : 字符串长度
* $font : 字体的路径,需要自己下载特殊字体
* $captcha: 验证码内容
*/
$len = strlen($data);
$font = './font/texb.ttf';
$captcha = ""; // 这一步不能少,不然会出现报错,设置一个空的变量
for ($i = 0; $i<4; $i++)
{
$textcolor = imagecolorallocate ($img, rand(0,100), rand(0,100), rand(0,100));
$index = rande (0, $len-1);
$indexstr = substr ($str, $index, 1);
$captcha. = $indexstr;
$x = 10+$i*20;
$y = 20;
imagettftext ($img, 18 , rand(-50, 50), $x, $y, $textcolor, $font, $indexstr);
}
// 这里开启session
session_start();
// 用session 保存验证码内容
$_SESSION["captcha"] = $captcha;
// 设置格式输出画布
header ('content-type:image/png');
imagepng ($img);
// 最后销毁这个图片
imagedestroy ($img);
?>