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: Oct 2007
Posts: 47
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster

How to Password protect files / sections on web page ?

 
0
  #1
Nov 2nd, 2009
Hi,

I'm sorry in advance if this is the wrong section.

I wanted to know is it possible to password protect some files in web page ?
For example, If someone wants to download file, browsers requests password(one for all visitors), idea is that some files and/or sections of web site is accessible to those who know the password..

Any advice , help much appreciated !
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #2
Nov 4th, 2009
try to code something like this -
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function validate()
  2. {
  3. var truePassword = 'test';
  4. var password = prompt('Enter the password','');
  5. alert(">>"+password+">>");
  6.  
  7. if(password !='' && password !=null)
  8. {
  9. if(password != truePassword)
  10. {
  11. alert("You don't have download permissin for this");
  12. }
  13. }else
  14. {
  15. alert("Enter the password");
  16.  
  17. }
  18. }
"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: Oct 2007
Posts: 47
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #3
Nov 4th, 2009
where in code should I put this php ?

is it for single file or for section in web page ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #4
Nov 4th, 2009
Originally Posted by wonderland View Post
where in code should I put this php ?

is it for single file or for section in web page ?
Does it look like a PHP
It may work against the single link which will prevent the download without entering the password
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function validate()
  2. {
  3. var truePassword = 'test';
  4. var password = prompt('Enter the password','');
  5. //alert(">>"+password+">>");
  6.  
  7. if(password !='' && password !=null)
  8. {
  9. if(password != truePassword)
  10. {
  11. alert("You don't have download permissin for this");
  12. return false;
  13. }
  14. }else
  15. {
  16. alert("Enter the password");
  17. return false;
  18.  
  19. }
  20. }
It may still need some modification to it get working
Last edited by network18; Nov 4th, 2009 at 6:34 am. Reason: modified function
"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: Oct 2007
Posts: 47
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #5
Nov 4th, 2009
whoops I'm sorry, don't know why I assumed that ..


if I have a .pdf file for example where should I put this code, or where in this code should I put this .pdf address ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #6
Nov 4th, 2009
Originally Posted by wonderland View Post
whoops I'm sorry, don't know why I assumed that ..


if I have a .pdf file for example where should I put this code, or where in this code should I put this .pdf address ?
call this function on click of the link, from where you download the pdf file.
"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: Jul 2006
Posts: 882
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 142
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #7
Nov 4th, 2009
Originally Posted by network18 View Post
call this function on click of the link, from where you download the pdf file.
This would still allow for downloading without password, just by looking at the page source.

Another way would be to put the pdf in a separate folder on the server, and password protect it (using your cPanel, htaccess, or whatever you're using).
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 47
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #8
Nov 4th, 2009
Do I call function like this ?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="faili/materiali/brosuras/maskesana.pdf" target="_blank" onclick="function name">
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #9
Nov 4th, 2009
Originally Posted by wonderland View Post
Do I call function like this ?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="faili/materiali/brosuras/maskesana.pdf" target="_blank" onclick="function name">
yes, its doesn't seem to be fullproof, even if after some modification to it
"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: Oct 2007
Posts: 47
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #10
Nov 4th, 2009
It doesn't seem to work:

I wrapped code you provided in js tags (otherwise code showed as plain text on page)

Edited link like this
<a href="faili/materiali/brosuras/maskesana.pdf" target="_blank" onclick="function validate">
Last edited by peter_budo; Nov 5th, 2009 at 7:08 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC