Checking for going up a Directory
I have been working on flatfile and directory system in PHP and not that I have got the script working I want to make it more secure. What I have is one directory with sub-directorys insided them and insided the subdirectorys are about 20 files each.
Forexample:
directory/
sub1/
sub2/
When the script is working out what directory to open it works like this:
directory/$subNum/$filename
What I want to be able to do is stop people from going down directorys (../../filename) because this could be a big security risk. What I want to know is if there is a better way than !preg_match('../',$filename).
Ragnarok
Junior Poster in Training
94 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
I would think that would suffice. Does anyone here think that it would still be a security risk? The only thing I could see still being a problem is that someone could still manually enter the directory URL into their browser for access to the files.
cscgal
The Queen of DaniWeb
19,433 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
there is a slight problem with that fact that I am making it an open source script
Ragnarok
Junior Poster in Training
94 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0