PHP图像字符水印居中

[php]
<?php
//让图像上字符串居中
header("content-type:text/html;charset = utf-8");
//(1)创建画布
$filename = "./images/02.jpg";
$img = imagecreatefromjpeg($filename);
$str = "WELCOME to liuguofeng.com";
$font = 5;
//(2)分配颜色:
$color1 = imagecolorallocate($img,255,0,255);
$color2 = imagecolorallocate($img,255,0,255);
//(3)获取画布宽度和高度
$imgWidth = imagesx($img);
$imgHeight = imagesy($img);
//(4)获取字体尺寸
$fontWidth = imagefontwidth($font);
$fontHeight = imagefontheight($font);
//(5)计算字符串的起始坐标
$x = ($imgWidth-$fontWidth*strlen($str))/2;
$y = ($imgHeight-$fontHeight)/2;
//(6)写入一个字符串
imagestring($img,$font,$x,$y,$str,$color1);
header("content-type:image/jpeg");
imagejpeg($img);
//(7)关闭图像
imagedestroy($img);
?>
[/php]

PHP通过HTTP请求防盗链

anti-theft_chain.php

[php]
<?php
header("content-type:text/html;charset=utf-8");
if(isset($_SERVER['HTTP_REFERER']))
{
//域名对比,一致下载,不一致跳转到错误页面
//strpos: 查找字符串首次出现的位置
if(strpos($_SERVER['HTTP_REFERER'],"https://blog.liuguofeng.com")===0)
{
echo "您可以下载软件了";
}else
{
echo "请从本网站下载";
}
}
?>
[/php]

anti-theft_chain.html

[html]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试页面</title>
</head>
<body>
<a href="https://blog.liuguofeng.com/anti-theft_chain.php">测试页面</p>
</body>
</html>
[/html]

PHP隐藏下载地址

download.php

[php]
<?php
//获取传递的文件名
$filename = $_GET['filename'];
$pathname = "$./download/$filename";
//以只读方式打开文件
$handle = fopen($pathname,"rb");
//返回数据的内容类型
//'octet-stream'八位二进制流
//'content-desposition:attachment'以附件形式打开
header("content-type:application/octet-stream");
header("content-despositon:attachment;filename=$filename");
//循环读取指定大小的内容,并输出
while($str=fread($handle,1024))
{
echo $str;
}
//关闭文件
fclose($handle);
?>
[/php]

download.html

[html]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="download.php?filename=test.jpg">下载图片</a>
<br>
<a href="download,php?filename=test.mp4">下载视频</a>
</body>
</html>
[/html]

用一条 SQL 语句展示需求用户列表

数据库的如下数据表 scores 记录用户得分历史,uid(int) 表示用户 ID,score(int) 表示分数,date(date) 表示日期,每个用户每天会产生多条数据 (示例:uid 3, date 2017-03-17)

现在需要一份用户列表,这些用户在 2017 年 3 月份的 31 天中,至少要有 16 天, 每天得分总和大于 40 分。用一条 SQL 语句表示。

select uid,count(1) from 
(
select date,uid,sum(score) sum from scores 
where substr(date,1,7)='2017-03' 
group by date,uid 
having sum(score)>40 
) cc 
group by uid 
having count(1) >=16