PDA

View Full Version : protecting pdf files using php


mangofreak
11-11-2008, 02:52 AM
hey guys,

This is my situation. I have a db that stores my uploaded docs info. The files are store in a directory, say docs. IN roder to view the files you have to login - standard DW login form and authentication, then you see the dynamic table that displays a list of docs stored on the server. The problem is that anyone could possibly copy the url of my files and email them to someone else and paste the address and vie my files - mostly pdf and word files.


I was thinking that I could pass the id via link to a page called getdoc.php where the request is processed. my feeble attemp looks like this:


<?php
$varUsername = $_GET["MM_Username"];
$varURL = "http://www.mysite.com/docs/"
$varFile = $_GET["txtFilename"];

if ($varUSername) == "True";{ Then

Header("Location: $varURL + varFile");
else
Header("Location: $http://www.mysite.com/login.php");

}
?>

any help to make it work will be much appreciated.

Javier

davidj
11-11-2008, 05:46 AM
store the content in the db and create the pdf on the fly

once downloaded destroy the pdf

also give the pdf a complex naming convention

davidj
11-11-2008, 06:43 AM
ok mate

here you go...

this creates the PDF and stores it in memory therefore there is no pdf to navigate to


$mypdf = PDF_new();

PDF_open_file($mypdf, "");

PDF_begin_page($mypdf, 595, 842);

$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);

PDF_setfont($mypdf, $myfont, 10);

/// text here ////////////////////////////////////////////////////////////////
PDF_show_xy($mypdf, "text line 1", 50, 750);
PDF_show_xy($mypdf, "text line 2.", 50, 730);
//////////////////////////////////////////////////////////////////////////////

PDF_end_page($mypdf);

PDF_close($mypdf);

$mybuf = PDF_get_buffer($mypdf);

$mylen = strlen($mybuf);

header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen01.pdf");

print $mybuf;

PDF_delete($mypdf);



Note: your php install needs the pdf library installed