Am pretty much new to php. I hve a php site with user login, i hve maintained session. I hve pdf download in blog and articles page.
I hve to show the pdf for all, but it should be downloadable only for registered users, for others when they click it i want to show a alert “Please sign in to Download”.
i hve placed a downloadable pdf in Blog and Articles page. Now only the register user can see the pdf files. Bcoz i hve hide it initially and after logging in i hve revealed it.
What i want is, i hve to show the pdf for all users, but only registered users can able to download it. for others it should show a alert like “sign in to download”
Am pretty much new to php. I hve a php site with user login, i hve maintained session. I hve pdf download in blog and articles page.
I hve to show the pdf for all, but it should be downloadable only for registered users, for others when they click it i want to show a alert “Please sign in to Download”.
i hve placed a downloadable pdf in Blog and Articles page. Now only the register user can see the pdf files. Bcoz i hve hide it initially and after logging in i hve revealed it.
What i want is, i hve to show the pdf for all users, but only registered users can able to download it. for others it should show a alert like “sign in to download”
You should have a php page which downloads the file and pass the downloading file to that file in query string. For example save the following script in download.php file. (I assume you save download.php file in the root).
if($user_is_logged_in){
$filetodownload = addslashes($_GET['filename']);
if(file_exists($filetodownload)){
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $filetodownload . '"');
readfile($filetodownload);
die();
}
}
else{
echo 'You must login to download the file.';
}
Use mod_rewrite to redirect all requests for .pdf files to a PHP script. That script looks at the session to determine whether to show the “sign in to download” message, or send the appropriate headers and pass the PDF data through.
I’ve done a bunch of stuff like this, and I suggest using a slightly different approach that simplifies the process:
You can circumvent the need to create user registration by simply using a form where users enter a form and check off the documents they want to download. Then use PHPMailer to send the documents. You can log the users email or send it to yourself at the same time.