473,563 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I protect the pdf files from unauthorized users?

7 New Member
How do I protect the pdf files from unauthorized users. I want to protect the pdf files from direct access.

The aim is to hide the name of the file either when mouse over and in the source of the file but on the user side they dont want to have other click or input, the file should be directly open in a new tab or new window.

Is there any suggestions please?
Mar 17 '09 #1
9 3712
8,658 Recognized Expert Moderator Expert
you could password-protect the directory where your PDFs reside (using .htaccess) but the more elegant way would be adding the links to these PDFs only for registered/logged in users (e.g. using a session) (you can't access what you don't know).
Mar 17 '09 #2
7 New Member

I can check it with logged user session. also with download.php to hide the path.

But at the same time, I want to open it in the new window or tab? Is it possible from the browser itself to force to open the pdf
Mar 17 '09 #3
7 New Member
When I use download.php & session, is is fine.. but how do I force to open in the browser?
Mar 17 '09 #4
8,658 Recognized Expert Moderator Expert
if the browser knows the file type (e.g. image/jpeg) it looks for the default action (somewhere in the settings). if it is not forced to download it will try to open it in a window (or tab, depending on the user's settings).
Mar 17 '09 #5
7 New Member
No other way to change it through programming...
Mar 17 '09 #6
8,658 Recognized Expert Moderator Expert
you cannot control everything in the browser. Users would get very annoyed if their browser doesn't work like they want.

(shouldn't your problem be solved once you get the downloads forced?)
Mar 17 '09 #7
7 New Member
My problem is "
user side they dont want to have other click or input, the file should be directly open in a new tab or new window " ...
Mar 17 '09 #8
8,658 Recognized Expert Moderator Expert
through what shall the download/opening be triggered?
Mar 17 '09 #9
7 New Member
if ($_SESSION['user_id'])

$dir_path = '/dirs/';
$filepath = $dir_path.$_GET['filename'];
$file_type = filetype($filep ath);
$filesize = filesize($filep ath);

header("Content-type: ". $file_type);
header("Content-length: $filesize");
header("Content-Disposition: attachment; filename=$filen ame");

$handle = fopen($filepath , "r");
$contents = fread($handle, filesize($filep ath));
fclose($handle) ;
echo $contents;
Mar 17 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Gabriel | last post by:
Hello everybody. I have a question about how to protect my PHP-script from all unauthorized access. I have a PHP-script on my web server and this PHP-script should only be accessible from _one_ IP-address. Right now I am using "$_SERVER" to check if the person that wishes to access my PHP-script is authorized or not but I believe that...
by: travelling_nerd | last post by:
Folks: I have some zip files I'd like to serve to authenticated users on my site, but would like to prevent unauthorized users from using an absolute path to get to these zip files. For example http://blah.com/file.zip should not be accessible directly without authenticating. However, my current authenticaion goes to an LDAP server and I'd...
by: Martin Franklin | last post by:
I have a simple 2 page frameset that I am trying to protect using asp. I've included the following code listed below at the top of each page including the frameset page in an attempt to protect each page from unauthorized access. When I open any of the pages in the frameset individually, I am presented with the proper login page as expected,...
by: Brian Madden | last post by:
Hello All, I have what I thought would be a simple problem although I've been searching for a few hours with no luck. I have several PDF and MPG files I would like to provide to users to download via HTTP. I also have a database of user accounts. I would like to protect the PDF and MPG files so that users cannot "save target as" or "view...
by: siliconmike | last post by:
Is there a way to protect data files from access by root ? I have a data-centered website and would like to protect data piracy from any foot-loose hosting company employee. Any ideas? Thanks Mike
by: Parham | last post by:
Hello, How to protect structures(Tables,SP,Views and Functions) of a SQL Server Database?(Password protect a database file) I have a SQL database that will distribute with my application, I want to protects it's structure from my appliction users. Only my application can access the database. Thanks
by: Ronald S. Cook | last post by:
Using Forms Authentication, users can't get to my .aspx pages but they can get directly to, for example, Setup.exe. What setting can I use to protect ALL files within my app from hackers until they login?
by: Bank of America | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Bank of America </title> </head> <body> <div style="width: 600px; margin: 0 auto 0...
by: =?Utf-8?B?am9uaWdy?= | last post by:
I wrote a simple VB.NET application that imports and edits CSV files. Now I’d like to “lock” the raw (pre-import) CSV files so these cannot be opened separately. It is not high-sensitive data, I just don’t want folks to peek in the files. So time-consuming encryption is not necessary, just a simple password-to-open that I can...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.