Jump to content

Protecting directory/files


Javrixx

Recommended Posts

*** UPDATE ON MY LAST POST, PLEASE READ THAT AFTER READING THIS FIRST POST, THANK YOU ***


Hi, I'm really new to PHP.  Basically I'm setting up a few things for my work.  I'm adding a feature that lets clients login and view certain .xls files and what not.  It will be their results that our company provides for them...

So I've almost got the login part of it done, I don't think I'll have too hard of a time getting the rest setup, but now that I'm thinking about it, I think I have a problem.

Client A needs to access his .xls files.
Client B needs to do the same thing.

All the files are stored in, let's say, /clientfiles directory.


I need to make it so only Client A can access his files and no one else's files.

Maybe I can make it a bit clearer.  Client A logs in with the username and password I provide him (he can change his pass).  On the next page it says welcome so and so and you have X amount of results ready for download.  I was thinking I was just going to generate the link using php according to what the filename is in the mySQL database.  So anyway, he clicks the link that lists all the results .xls files to download...

Let's say they're all stored at http://www.mydomain.com/clientfiles.  So he has 3 files listed there:
http://www.mydomain.com/clientfiles/file1.xls
http://www.mydomain.com/clientfiles/file2.xls
http://www.mydomain.com/clientfiles/file3.xls

Now, what is to stop him, and anyone else to just going to http://www.mydomain.com/clientfiles/ and seeing all the files in that directory and being able to download them?  Is there a way I can fix this so only the logged in client can access only those files?  Or am I going to have to do something totally different as a solution?

Any help is much appreciated.  I really don't know too much about PHP, so far I've been using tutorials and using "trial and error" changing the code here and there to suit my needs.  I do know HTML like the back of my hand, so I do understand the basics and how PHP functions, I just don't know the commands, etc, for it yet.  Thanks again.
Link to comment
Share on other sites

Thanks for the responses guys.

Ok so I can do either one of those, but what if someone finds the users directory or finds the directory with all the users in it.

I just don't want someone to be able to find out the download path and download files, I need it to be secure so only those people can download the files.  Even if I only list it for one particular user, anyone who KNOWS what that user directory is could still download it.  For example:

http://www.mydomain.com/users/useridrandom1234/file1.xls

So say someone goes to http://www.mydomain.com/users

They can then see the directory, then it's just a matter of trial and error before they could possibly find the files.

I know the chances are unlikely, but we're talking about pretty secure information about people and I need it to be protected.
Link to comment
Share on other sites

if someone gets the full url then they may still be able to see them! Without done the reading have a look at locking the directories and only opening them vis teh script - may be that chmod will be more than enough for your needs.

No expert on this but you would need a setting that denies public but allows owner of the dir to access - that way php should be able to chmod the directory.
Link to comment
Share on other sites

[quote author=ToonMariner link=topic=107930.msg433685#msg433685 date=1158175056]
if someone gets the full url then they may still be able to see them! Without done the reading have a look at locking the directories and only opening them vis teh script - may be that chmod will be more than enough for your needs.

No expert on this but you would need a setting that denies public but allows owner of the dir to access - that way php should be able to chmod the directory.
[/quote]So, we could only let the admin (the admin of the website) to access some files? Like the user won't get the file directly, but it is a php function that will download the file for the user? The php function will only download the file if the user can (like verify the loggin etc.)

If I use my ftp client, I can change the file properties (chmod) like the following screnshot.
[img]http://benice.beadventure.ca/g/images/chmod.png[/img]
We can Execute because it is a folder, if it is a *.jpg (for exemple), we won't get the Execute command, but only Read.

Well I have questions about this:
[list]
[*]What is Group?
[*]Can we remove the Read for a file for the "World" and have a php function that will download the file?
[*]If yes, what if that function?[/list]

Thanx for all the help.
Link to comment
Share on other sites

    * u (user), which represents the permissions granted to the owner of the file,
    * g (group), which represents the users who are members of the file's group, and
    * o (others), which represents any users who are not the owner of the file or members of the group, or
    * a (all), which represents all three of the above.

Thank you,
TopLancers.com
Link to comment
Share on other sites

Ok so I'm almost to the point where I need to implement this.

I think I'm down to 2 options...

1) Use the users ID and make a random folder, stores the files in it... for example, say user123 logsin and wants to see their files.  On the database, they're userid is say... 555.  So I make a new folder in the userfiles folder, starting with the user ID and then some random stuff after that: 555fdjf78nab5jk6diap227yu46/file1afd87b93bfi3a.xls

So the path to download that would be http://www.mysite.com/userfiles/555fdjf78nab5jk6diap227yu46/file1afd87b93bfi3a.xls

It will be easy for me to find, because the user ID is still the first part of the directory, as would be the file name that they need, but the rest is so random people would PROBABLY never find the full path for that file...  Am I right about this?


2) Someone had mentioned to me that I can store the files on the server, but not public.  When the user logins in, I would make a php script to create a random temporary folder and move the needed files for that user to the new temporary folder.  After the user logs out the temporary folder is deleted, thus the user's files are never really public, only for a short time when that user is logged in and needs the files.

Now, my big issue with this is, I lack the knowledge to set something up like this that is so complicated.  I haven't looked for any tutorials, but that it is pretty specific and don't know if I'll be able to find something.  I'm about 2 weeks away from having to really set this up so ANY feedback on this is highly appreciated.
Link to comment
Share on other sites

[quote author=Javrixx link=topic=107930.msg438137#msg438137 date=1158770719]
2) Someone had mentioned to me that I can store the files on the server, but not public.  When the user logins in, I would make a php script to create a random temporary folder and move the needed files for that user to the new temporary folder.  After the user logs out the temporary folder is deleted, thus the user's files are never really public, only for a short time when that user is logged in and needs the files.[/quote]
I'm sure that this is a good solution, but you don't need to move the file. Their must be a way to download it...

I'll search.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.