Sending PDF password via php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mince
Forum Commoner
Posts: 25
Joined: Mon Aug 03, 2009 9:36 am

Sending PDF password via php

Post by Mince »

Hi All

I have been struggling with this for a while. On my intranet site I create PDF's, and assign them a password (they all have the same password). Now i want to know if there's a method to send the pdf document the password via php? I assume it would be done here:

Code: Select all

$file = "../../../base/ScanReport.pdf";

if (file_exists($file)) 
{
    header('Content-Description: File Transfer');
    header('Content-Type: MIME');
    header('Content-Disposition: inline; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file)); 
    ob_clean();
    flush();
    readfile($file);
    exit;
}
else
{
	echo "<font color = 'red'>Something went wrong, file not created.</font>";
}
The reason why I need the php to send the password is because when users open the file using the intranet, they should be allowed to see it automatically as they are already logged in. A person who finds the document on the server, for example, would have to type in the password manually to get access to the document.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Sending PDF password via php

Post by yacahuma »

I dont think you can do that. What you should do is send the pdf with no password when the user is logged in.
Mince
Forum Commoner
Posts: 25
Joined: Mon Aug 03, 2009 9:36 am

Re: Sending PDF password via php

Post by Mince »

Thanks for the reply.

Unfortunately, the pdf's are created and stored on the server, and have to be password protected due to privacy laws. These pdfs are not created on the fly, so i can't just create them without the passwords.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Sending PDF password via php

Post by yacahuma »

why not remove the password and then sent it, only when the user is logged in?
Post Reply