/    Sign up×
Community /Pin to ProfileBookmark

password protecting folders

Hi – just wondering if someone can explain a good way of doing this…

I have a folder of pdfs that I’d like to password protect. Obviously I could use .htaccess for this, but I’d like an growing number of passwords taken from a MySQL table to be used to access this folder. I’m wondering about developing a script for when a user registers, which adds a line into the .htaccess file that adds their password.

Is this be the best way of doing it, or are there far simpler ways of dynamically protecting a folder?

Thanks muchly for any help ?

Nick

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarOct 10.2007 — you could put the files in a directory that's protected by htaccess that no-one gets the password to, then create a download.php file that check passwords against the DB, if success full it reads in the contents of the file specified in a querystring(eg: download.php?file=meap.pdf ) and after echoing headers prints the file contents for download.

I don't have time to go over this in full detail now, or produce a sample code, but if you read up on fopen, fread and the basic mysql functions from php.net you should get a good idea of what to do.
Copy linkTweet thisAlerts:
@sloLearnerauthorOct 11.2007 — ? Scragar, thank you so so much for taking the time out to give that post - that's solved it for me! I hadn't thought of using header functions like that, and that'll work brilliantly.

Yours gratefully

Nick
×

Success!

Help @sloLearner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...