Forum Moderators: coopster
I'm unable to implement the normal .htaccess method used for images, because frequently legitimate downloaders requesting the files from within our site, do not provide an http referer for pdfs.
Is there an equivalent method in php? I searched but couldn't find anything.
I'm assuming you're running ASP.NET; if you're not, then hopefully these suggestions will translate to whatever development environment you're using.Let's say your server is hosting your web site "http://superwebsite" in the virtual folder "C:\Inetpub\wwwroot\superwebsite". You could store your docs in "C:\superwebsite\Docs". There is no way to navigate to that folder, and there is no direct URL that references that folder.
So, now no-one can get at these documents directly, but you want authentic visitors to your site to get at them. Instead of using hyperlinks (or whatever control that generates the <a href...> thingy ), place a button on your web page.
In the click event for the button, do something like this:
// Read the file into a buffer
string sf = @"C:\superwebsite\Docs\supermanual.pdf";
FileStream fs = new FileStream(sf, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);byte[] df = binReader.ReadBytes((int)fs.Length);
br.Close();
fs.Close();// Transmit the buffer in the response
Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.BinaryWrite( df );
Response.Flush();
Response.End();That's it. When your visitors click the button, the server responds with the requested document.
Creating the directory below the web root is no problem - I placed it here: /home/username/pdf/
However, I don't know how to program using php, so any assistance with the code would be very welcome.
A good article is this [devpapers.com...] Also u may want to ask for extra help here in [webmasterworld.com...]
Unfortunately, as I mentioned in my original post, the .htaccess method that works for hotlinked images does not work with PDF files.
That method relies on there being a referer string from our site or a blank referer (necessary because some ISPs like AOL don't send referers). Most downloads initiated from within our site, happen with no referer string sent, which is identical to what happens when someone downloads a pdf via a link from a remote site.
That is why I need a different method.
Path to the web: /home/username/public_html/
Path to new pdf directory:/home/username/pdf/
However, I do not have a php script to serve them or have even the vaguest idea how to do authentication. That was the purpose of my original request. I'd really appreciate some assistance to locate suitable scripts and some basic instructions for a php newbie who is floundering badly.
TIA.
that does put you in a tough spot
maybe set a cookie on your site and only allow those with the cookie to download, this would require a script to do so
I don't know of any scripts that do pdf protection, have you looked through any of the ebook protection type scripts? Those are usually pdf's
as far as a php dowmload script this search [google.com] shows a bunch of threads, though the problem is with that you need to find a way to auth these folk.
maybe a cookie is the way to go