它的作用是什么?
问题:显然第4步(如果登录然后显示PDF文件)由于htaccess的行为而失败。
问题:我该如何解决这个问题?
由于
htaccess的:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteRule ^(.*)$ /validate.php?filename=$1 [L]
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.
}
答案 0 :(得分:2)
在//User should be eble to see the PDF file now.
步骤中,只是输出文件,而不是将用户重定向到pdf文件。如下所示:
$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);