形如/image/vip/2019/11/xxx.jpg的文件被内部重定向到/jpg.php?s=/image/vip/2019/11/xxx.jpg,php文件中检查cookie,进行权限校验,有权限就输出图片,没有权限就302到缩略图。
location ~^/image/vip/.*.jpg$ {
rewrite ^(.*)$ /jpg.php?s=$1 last;
}
<?php
require_once(dirname(__FILE__).'/config.php');
if(isset($_COOKIE["token"])){ // 是否有登录令牌
$token = $_COOKIE["token"];
$redis = new Redis();
//连接
$redis->connect(DB_REDIS_IP, 6379);
$redis->auth(DB_REDIS_PWD);
$tr = $redis->get($token);
//var_dump($tr);
if($tr==False){ // 登录令牌是否有效。
}else{
$file = dirname(__FILE__).$_REQUEST['s'];
header('Content-type:image/jpg');
echo file_get_contents($file);
}
}
header("Location:/thumbnail/".$_REQUEST['s']);
//phpinfo();
?>