Javrixx Posted September 13, 2006 Share Posted September 13, 2006 *** 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.xlshttp://www.mydomain.com/clientfiles/file2.xlshttp://www.mydomain.com/clientfiles/file3.xlsNow, 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 13, 2006 Share Posted September 13, 2006 why not make directorys with the users id from the database and any file you want that user to have copy to there directory.then select that user were id='$id'"; and a link to his dir via his id. Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 13, 2006 Share Posted September 13, 2006 or you can do an if statement in the filesif username is client A show itelse don't show ityeah that is not actual code, just theory code. Quote Link to comment Share on other sites More sharing options...
Javrixx Posted September 13, 2006 Author Share Posted September 13, 2006 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.xlsSo say someone goes to http://www.mydomain.com/usersThey 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 13, 2006 Share Posted September 13, 2006 stick a index.php in it with a redirect to the index page thats the easy way.[code]<?phpheader("location: index.php");?>[/code] Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 13, 2006 Share Posted September 13, 2006 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 Link to comment Share on other sites More sharing options...
redarrow Posted September 13, 2006 Share Posted September 13, 2006 ok then i got a better way make a random 8 number figure then add that to the members database table then provide that to make the directorys that better and easer.the posabilty of a user finding that number for the directory will be near to inpossabilty. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 13, 2006 Share Posted September 13, 2006 easier???? Random 8 didgit number could be found in a couple minutes with a simple brute force attack!seems a lot of hassel where as umask and chmod would do the trick - provided what I said was possible - which I am sure it is. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 13, 2006 Share Posted September 13, 2006 it is for linux redhat but not windows so how do us windows user get the same effect. Quote Link to comment Share on other sites More sharing options...
Javrixx Posted September 14, 2006 Author Share Posted September 14, 2006 Ok I will try that. I'm not really up to that stage yet, but I will be within the week. Do you by chance know what script that is or where to get it? Quote Link to comment Share on other sites More sharing options...
Atomg Posted September 15, 2006 Share Posted September 15, 2006 [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. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted September 15, 2006 Share Posted September 15, 2006 * 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 Quote Link to comment Share on other sites More sharing options...
Atomg Posted September 17, 2006 Share Posted September 17, 2006 Ok, thx.Now can we adjust those chmod settings and make only Read/Write/Execute for users and put a php function that start the download? Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 i was thinking if you protect a folder with images in and disable side click the user can not get the pic but if the user downloads the whole website i think they will get all images not sure? Quote Link to comment Share on other sites More sharing options...
Javrixx Posted September 20, 2006 Author Share Posted September 20, 2006 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.xlsSo the path to download that would be http://www.mysite.com/userfiles/555fdjf78nab5jk6diap227yu46/file1afd87b93bfi3a.xlsIt 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. Quote Link to comment Share on other sites More sharing options...
Javrixx Posted September 22, 2006 Author Share Posted September 22, 2006 *bump* Quote Link to comment Share on other sites More sharing options...
Atomg Posted September 23, 2006 Share Posted September 23, 2006 [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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.