File access problem
Hi frnds,
I have built an information maintenance system where files can be uploaded. Anyone can view those files.
But, the problem is when a file is viewed in the browser at that time if someone just copy the URL in some text file after that any body from any where can view that file by just pasting that URL in the browser's address bar.
How to prohibate this thing. PLZZZZZZZZZZZZZZZZZZZ help me...............
its verrrrrrrrrrrrrrrrry serious problem..............
Thanxxxxxxxxxxx.
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
Sorrrrrrry everyone,
actually i did not clear the problem to you, My files are in ".pdf" format...
Suppose,
http://localhost/information/sample.pdf
can be viewd ....... no login is required to do so..
if I cross the browser and after that in a new browser if I paste this URL then it should not be viewd.......
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
Okay, try something like this then.
Pass the filename to one php script and if the requesting referer is from your site, deliver the content...otherwise deliver an error page.
<?php
// example argument passed with file name
// http://yourhost.com/view.php?file=test.pdf
$file = $_GET['file'];
if ( $_SERVER['HTTP_HOST'] == 'yourhost.com' ) {
header( 'Content-type: application/pdf' );
print file_get_contents( 'secret_directory/'.$file );
} else {
header( 'Location: http://www.google.com/' );
}
?>
Hope this helps
Okkkk sir,
but when the file will be viewed the whole path will be in the address bar.........and there is the problem persist........
thanx for reply.......
plz help me to fix it...
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
ya i suppose now u gave correct explanation of ur problem
now only possible things are .htaccess
i need others to speak on this
Anyone to rescue neil of his situation??
easy bit... neil
lets see who solves first
take care
anwar jamal
Thanx buddy...............thanx for support...........
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
You're missing the point...you cannot hide the address to the PHP script that displays the requested file, but it doesn't matter since the file is in a directory that will NOT be displayed in the address bar (since it is being printed directly through the PHP file) and that directory can even be located outside of the public server directory, but PHP can still access it and browsers cannot. But the main point is that the PHP script is checking if the requesting browser is coming from a page on your site, and if it's not, it doesn't show the file...
The real problem you will be facing is that anyone can save a copy of your PDF document to their local computer and unless there is some built in PDF security (none that I know of) they have total control over that document off of your website...there is no way around this that I know of.
People always try to protect content on web pages, sometimes with javascript overriding the browser functions, and many other ways...it really almost NEVER works when someone is determined. The only real way would be to use a password to protect the files from some people, but those you gave the passwords to would still be able to save the document and do what they wanted with it.
That's just the way it is.
ya ya I got your point .........
Now is there any directory permission factor can be acomplished that only authorised persons can view those file other than none can access...
If you have any idea can you plz share with me
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
You might need to be more specific. Are you one a linux server or windows...are there accounts set up that can tell one person apart from another?
What I know is you want people to be able to view your pdf files but only one your website...but through the page you specify, not directly through the URL.
Maybe you could explain what your exact situation is and we can find a different approach.
exactly i want what you said on your 2nd paragraph.........and it is necessary for both linux & windows environment
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
I think the answer I gave then should work...as good as anything.
But remember, there is no way to stop people from saving the PDF file to their computer when they view it -- no matter how they view it, since Adobe Reader has a "Save Copy" button built into it. (Unless I'm missing something about PDFs ?)...
So once they have it viewed in their browser, I don't know of anyway to keep them from saving a copy on their computer to view later or send to friends in an email or something like that.
You might look on the Adobe website for more information on this subject, to see if there is some security you can use to keep people from saving a copy of your PDF file to their computer. If there is, then my solution should be perfect combined with that function.
Sorry...maybe someone else knows some trick I'm missing here.
Good luck
Thanx dude..........you people have taken part in this prob....that's enough for me
lets see what next.............
thanx once again..
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
Is there exist any file function like fopen(),
fread() etc. using that i can open my pdf file in the browser...
e.g. scribd.com dose
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2