944,127 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Nov 2nd, 2009
0

How to Password protect files / sections on web page ?

Expand Post »
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 !
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
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. }
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
where in code should I put this php ?

is it for single file or for section in web page ?
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
Click to Expand / Collapse  Quote originally posted by wonderland ...
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
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
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 ?
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
Click to Expand / Collapse  Quote originally posted by wonderland ...
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.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
Click to Expand / Collapse  Quote originally posted by network18 ...
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).
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
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">
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
Click to Expand / Collapse  Quote originally posted by wonderland ...
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
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: How to Password protect files / sections on web page ?
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)
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: onClick code dont now how to use.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Warning Message on Browser Close





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC