[英]Either override behaviour of htaccess or a different solution for file access from URL
What it does? 它能做什么?
Problem: Obviously 4th step ( If logged in then show PDF file ) fails because of the behaviour of htaccess. 问题:显然第4步( 如果已登录,则显示PDF文件 )由于htaccess的行为而失败。
Question: How can I solve this issue? 问:如何解决此问题?
Thanks 谢谢
HTACCESS: .htaccess中:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteRule ^(.*)$ /validate.php?filename=$1 [L]
validation.php: validation.php:
//STEP 1) Take a log
$file = 'log.txt';
$current = file_get_contents($file);
$current .= (isset($_GET['filename'])) ? $_GET['filename'] : '?';
$current .= " --- " . date('H:i:s') . "\n";
file_put_contents($file, $current);
//STEP 2) Authenticate login
session_start();
if (! isset($_SESSION['user']))
{
session_write_close();
header ('Location: /login.php');
exit();
}
else
{
//User should be eble to see the PDF file now.
}
In the //User should be eble to see the PDF file now.
在
//User should be eble to see the PDF file now.
step, instead of redirecting the user to the pdf file, simply output the file . 步骤,而不是将用户重定向到pdf文件, 只需输出文件 。 So something like:
所以像这样:
$file = $_GET['filename'];
$filename = basename($file);
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.