How to Password protect files / sections on web page ?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2006
Posts: 856
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 139
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Practically a Posting Shark
 
0
  #11
34 Days Ago
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="faili/materiali/brosuras/maskesana.pdf" target="_blank" onclick="validate();">
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 549
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #12
34 Days Ago
Leave it, it wont work.Here is one more logic -
-redirect the user to another php page when he tries to download the pdf, adn check his username/password there.
-if username/password are right just get him back to the previous page or else directly exit or do whatever you wish.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training
 
0
  #13
33 Days Ago
There are 2 ways to securely do this. The first one is to make the download dir inaccessible without password (this is as said done in htaccess e.l. and not in you code). The other one is to put the file outside of you public_html-folder (http_root o.l. it might be called on a winserver) and use a script/program like php or C# to read the file and output it to the response-stream if the password is correct.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 37
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #14
33 Days Ago
I found out about htaccess few hours ago. Now I know how can I password protect a single html page. which was one of the things I needed.

But how can I password protect single file or better yet <a href> tag ? I don't know much about php etc. so I wanted to ask in this forum for some help, maybe someone know some tutorials regarding this ..
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training
 
0
  #15
33 Days Ago
Originally Posted by wonderland View Post
I found out about htaccess few hours ago. Now I know how can I password protect a single html page. which was one of the things I needed.

But how can I password protect single file or better yet <a href> tag ? I don't know much about php etc. so I wanted to ask in this forum for some help, maybe someone know some tutorials regarding this ..
Password-protecting a single a-href doesn't make sense. What does is to password-protect the file that the a-href points to. And if you already know how to password-protect a html-file my guess is that it shouldn't be much of a difference in password-protecting a pdf-file or a img-file etc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 37
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #16
33 Days Ago
Thanks, everything works great, I don't know why, but somehow I imagined this would be much harder :p.

Got 1 question though:

when I clicked on .pdf link (without .htaccess) it opened in a new tab/window. Now when I have .htaccess, browser opens new tab and asks for authorization , which is all great, but if i press cancel I get Authorization Required error page. Is it possible to somehow get redirected back to the page from which I opened that .pdf instead of error page ?
Last edited by wonderland; 33 Days Ago at 7:50 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training
 
0
  #17
33 Days Ago
I'm not shure about that. That's about server-settings, and not programming (.htaccess is too actually server-settings, but I'm not that familiar with it).
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC