GetDotted Domains

Viewing Thread:
"PHP unprotect / download file"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 01/08/05 at 12:44
Regular
"Peace Respect Punk"
Posts: 8,069
So currently I've got a login page setup that initially displays a login box. The submitted username & password are passed back to the same php page, which connects to a MySql database to ensure it is a valid user/pass combo.

If it is, the page displays all the files within a download folder. Now, I want this folder to be protected so no-one can simply type the URL of the folder (or one of the files contained within) and gain access. The only way I know of to do this is with .htaccess... If a folder is protected with .htaccess though, can I somehow unprotect it with the php page once a user has successfully logged on? Or is there some way of downloading the file with the php, as I'm under the impression server side scripts can still access .htaccess protected files/folders...?

Cheers in advance for any replies...
Tue 02/08/05 at 08:58
Regular
"Peace Respect Punk"
Posts: 8,069
Anyone have any experience using recursive PHP funcitons...?

Before I had a function to display the contents of the download folder, along with links to the download.php?file=(whatever) download for that file... But I also need users to have different 'levels' of access to files, and was going to do this by having the 'top level' users start from a high folder, while as 'low level' users start further down the folder heirarchy. So I need a function to display all files in their start folder and all files in any folder contained within, until all nested folders have their contents displayed.

Obviously I'll have to then check what level the user is on the download.php file, but the algorithm will pretty much be a combination of the one already written and the display folder contents algorithm.

Anyway, I wrote the showFolderContents function, and it works fine at first, except it just stops running... And the rest of the page (eg. footer) is not processed. Any ideas what could be causing this? The algorithm is recursive, calling itself upon finding a folder with the new starting directory and increasing the nested level (which is just there to add some "|-" things to make it look a bit prettier and easier to see what file is in what folder).

Anyway, any ideas about this? Chars.


EDIT: By the way, I'm testing it further, and it seems to deal with one nested level fine. It will display the contents of the initial start folder and any/all folders contained within. But if I add a folder in one of the already nested folders, it breaks... :-S


EDIT-2: I was being an fool. I had a while loop in the function which gets the "|-" thing based on what nested level the function is on and had forgotten to decrease the loop variable... Doh.
Mon 01/08/05 at 19:00
Regular
"NULL"
Posts: 1,384
Yeah, that's how it works.

Do a PHP file with the following code in:



That'll print the full path to the script.
Mon 01/08/05 at 18:52
Regular
"Peace Respect Punk"
Posts: 8,069
Nimco wrote:
> Is it a Windows platform? Using / will reference to the root of the
> operating system if it is Unix - not the root of the webserver.

Hmm, may be the problem... So I need to put something like /~username or whatever, and that'll be referencing the folder that is above the public_html...?
Mon 01/08/05 at 18:30
Regular
"NULL"
Posts: 1,384
Yup, it's really annoying though, cos it means you can't have much a folder structure with includes very easily, because whenever you use that include, you have to make sure the top files are at the same level.

Very annoying!
Mon 01/08/05 at 18:16
Regular
"Peace Respect Punk"
Posts: 8,069
Yeah, I found that. As I understand it, it's because the include statement is just grabbing all content from the included file and shoving it in the file that requested it.

So if there's nested includes, the top file calls an include, and it starts processing all that included files contents, so if there's an include in the initial included file, it all gets processed, then shoved in the initially included file, then that initially included file is going to be included in the top file for the browser to interpret.

So any refernces will have to be in the scope of the top file called.
Mon 01/08/05 at 18:02
Regular
"NULL"
Posts: 1,384
Is it a Windows platform? Using / will reference to the root of the operating system if it is Unix - not the root of the webserver.

By the way, has anyone else found problems with nested includes? Say you have an included file which includes another file, all the include paths have to be relative to the top level file.
Mon 01/08/05 at 17:24
Regular
"Peace Respect Punk"
Posts: 8,069
Got it to work eventually. Was setting the username & password $_SESSION variables as encrypted, then retrieving the user/pass from the Database and encrypting as well and comparing.

However, I'd forgotten the passowrd is stored as encrypted in the database too, so I had to add that encryption to the password $_SESSION variable before the second 'session' encryption...

Working now!


EDIT: One niggle I've been having throughout is absolute referencing... I've never had use for it before, so never used it, but I've been having problems referencing the 'top' folder where the 'downloads' folder is stored so people can't access any of the files within... I've now resorted to relative referencing, meaning a bunch of "../"s, which isn't a tragedy, I was just interested if anyone could tell me how it's done... I thought it was just "/(folder in top directory)", but that refused to work...
Mon 01/08/05 at 17:01
Regular
"NULL"
Posts: 1,384
Lol, shout if you need a hand.
Mon 01/08/05 at 16:54
Regular
"Peace Respect Punk"
Posts: 8,069
You need it at the top of both pages, the logon and download? Ah, yes, working now.

Well, not working. But the session is now. Just gotta put in some echoes and see what section is causing it to do... nothing.

Chars!
Mon 01/08/05 at 16:48
Regular
Posts: 10,364
Done a

session_start();

At the top of the page?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Easy and free service!
I think it's fab that you provide an easy-to-follow service, and even better that it's free...!
Cerrie
Everybody thinks I am an IT genius...
Nothing but admiration. I have been complimented on the church site that I manage through you and everybody thinks I am an IT genius. Your support is unquestionably outstanding.
Brian

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.