Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 10-17-2005, 07:50 AM   #1 (permalink)
Registered User
 
Join Date: Jul 2005
Posts: 24
OS: Windows XP


Restrict access to files in PHP

Hi,

just wondering how one would allow users to download a file only after they have authenticated through a login page using PHP.

For example:
Say I have a file file.exe which only those with a password and username can have access to; and this file is located at http://www.mysite.com/progs/file.exe. So members login to the page via their username and password and then a page appears with a link to the file. After hitting the link, they get the file.
I already know how to do all of the above in PHP, however the problem arises when someone enters the following in their browser; http://www.mysite.com/progs/file.exe and they get access to the file without having to go through the login page first.

Anyone have a solution or work-around to this problem.
DJ_Dance is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-17-2005, 08:31 AM   #2 (permalink)
TSF Enthusiast
 
Resolution's Avatar
 
Join Date: Sep 2005
Location: Louisiana
Posts: 1,091
OS: FreeBSD/Win98/2000/XP


If you are using Apache, it would probably be better to use .htpasswd. You could protect your entire web folder or individual files.
Resolution is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-19-2005, 08:25 AM   #3 (permalink)
Registered User
 
Join Date: Jul 2005
Posts: 24
OS: Windows XP


Resolution,

first and foremost thanks for the quick response.

I got the webpage up and running using the .htaccess files. I always wondered how websites used this particular type of authentication; I guess now I know.

It's very effective, but I actual had some trouble setting it up. The main (and really only) problem with using .htaccess file was the fact that you needed to know the full pathname of the .htpasswd (or file which contains the encrypted passwords). Since I'm not actually hosting the website on my machine, getting the full pathname of the page on the server hosting the website was the difficult part. Is there a way to actually get around this problem. This is the only issue I have about using .htaccess file; other than this, they're perfect. I tried playing around with how you specify the path in the file (including using the relative path to the file), but it only seems to like the full pathnames.
DJ_Dance is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-19-2005, 12:39 PM   #4 (permalink)
Manager, On the Web
 
E-Liam's Avatar
 
Join Date: Jan 2004
Location: Bracknell, UK
Posts: 929
OS: XP


Hi DJ,

use this little script.. Servercheck.cgi.

Upload to your cgi-bin and then just go to www.yourdomain.com/cgi-bin/servercheck.cgi

That will tell you all you need to know about paths to your server, including sendmail etc.

Cheers

Liam
__________________


My Mother suggested a family outing... so I told her Uncle Bob was gay. (Trevor D.)

Never argue with an idiot! They'll bring you down to their level and beat you with experience.

---------------------------------------------------------------------------------
A member of the Alliance of Security Analysis Professionals since 2004.
E-Liam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-19-2005, 06:59 PM   #5 (permalink)
Registered User
 
Join Date: Jul 2005
Posts: 24
OS: Windows XP


E-Liam,

Thanks for the link. I was actually trying something similar by writing a PHP script which did this. I soon realized that my ISP's servers don't support cgi scripts and this is where the website is being hosted. Maybe the only solution might be to pay for web hosting, where my site would be hosted on decent servers where you won't be so restricted.

It would still be really good if there was a way to get around what seems to be a really minor issue, but I can't image how you would actually go about it other than accessing the machine where the website is hosted.

On another note in regards to .htaccess files:
Is there a way to limit the number of retries the user gets when they enter in an incorrect password. On most sites which use .htaccess files, you only get like 3 tries before your redirected to another page warning you that your username/password was incorrect. By default, whenever I enter an incorrect password the authentication box just keep re-appearing until I hit cancel. It would be better if you could actually tell the user explicitly that they're entering in an incorrect password or username, since the current behaviour is also similar to when the .htaccess file can't find the .htpasswd file to authenticate the user. Therefore, it appears as if your .htaccess file is broken, rather than the username and password entered being incorrect.
DJ_Dance is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-22-2009, 11:08 AM   #6 (permalink)
Registered User
 
Join Date: May 2009
Posts: 1
OS: vista 64


Re: Restrict access to files in PHP

After couple of hours of reading on .htaccess for apache in windows - I finally figured out - You need to set the open_basedir directive in your php.ini file to restrict access to file system beyond the web folder. Considering it took my good amount of searching I added couple of articles on PHP security that applies for windows here:

http://oviya.me

Last edited by jaysupport; 05-22-2009 at 11:11 AM.
jaysupport is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-31-2009, 09:04 AM   #7 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 1
OS: Vista


Re: Restrict access to files in PHP

Hello,

I've read in another forum that a solution to this problem is to stor the files in a directory above the www directory. Therefore the users browser is unable to get to the page, but the PHP scripts can be pointed to it.

Is this a suitable solution and what are the drawbacks of using this method?
How would using .htaccess compare?

Thanks
julian213 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 08-03-2009, 06:27 PM   #8 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Restrict access to files in PHP

How much PHP do you know? If you are just wondering how you can protect a PDF or MP3 file or something, you can have the server parse PHP in specific filetypes, but it requires access to the .htaccess file again. Can you do that or not?

Do you need someone to write the PHP for you or are you set with that?
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 03:46 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85