PHP PDF Question

KahunaHube

Senior member
Aug 16, 2001
523
0
0
Hey all,

I'm making a website with a sessions and a login. Once logged in a person can view pdf documents, ex: http://www.mysite.com/pdf/doc1.pdf. How can I secure this url, so someone cant just type it in their browser and view the pdf without logging in. I want to do this all via php.. no directory passwords and such

Any advice is helpful, thanks!
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: mugs
http://us2.php.net/manual/en/function.header.php

See code below from that page, it basically accomplishes what you're looking for, other than authenticating the user which you'll obviously have to do yourself.

The only problem I see with that is that the file is still accessable from the web as you could still just examine the headers and type in the page name. I guess you could keep the files in a non-weaccessable place and just read/output them with the headers, but I'm certain that would be hell on memory.
 

mugs

Lifer
Apr 29, 2003
48,924
45
91
Originally posted by: amdfanboy
Originally posted by: mugs
http://us2.php.net/manual/en/function.header.php

See code below from that page, it basically accomplishes what you're looking for, other than authenticating the user which you'll obviously have to do yourself.

The only problem I see with that is that the file is still accessable from the web as you could still just examine the headers and type in the page name. I guess you could keep the files in a non-weaccessable place and just read/output them with the headers, but I'm certain that would be hell on memory.

Good point, but to see the headers you would have to have permission to download the file. I was going to suggest using mod_rewrite to rewrite /pdfs/doc.pdf as pdf.php?doc=doc.pdf, and in that PHP file you'd authenticate the user, read the PDF file and output it to the user. That would hide the actual location of the file, and if someone requested the file directly without logging in, you could reject it.

Edit: Looking at the code I posted again, the user would never see the original filename.
 

Beau

Lifer
Jun 25, 2001
17,731
0
76
www.beauscott.com
Originally posted by: amdfanboy
but I'm certain that would be hell on memory.

It's actually not.

I've done tests to see what it does to PHP and Apaches memory usages to stream large files, but using readfile just dumps them immediately to the output buffer, so no extra memory is used server side.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Beau
Originally posted by: amdfanboy
but I'm certain that would be hell on memory.

It's actually not.

I've done tests to see what it does to PHP and Apaches memory usages to stream large files, but using readfile just dumps them immediately to the output buffer, so no extra memory is used server side.

Very nice
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |