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.
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...
I have written a download.php file to force download of the file passed to it, if the information in the $_SESSION variable (set on the logon page) is valid logon information...
However, the first line of the code checks that the relevant $_SESSION variables are set (eg. $_SESSION['username'] & $_SESSION['password']) are both set... And it says they aren't.
I've echoed the variables, and nothing displays on the page, although on the logon page they are set and display fine...
I thought $_SESSION was a global variable so any variables I set in the $_SESSION array should be set in every page yes...?
Confused...
> Surely anyone can still access files though? Sounds like that'd work
> fine for .php files, but not for things you want the user to download
> or images or whatever...
Sorry, misread your post.
Ignore what I wrote.
Say your root webserver directory is: /usr/httpdocs/
Put the files in a folder such as: /usr/filestore/
Then have a file called "file.php" in /usr/httpdocs/ containing the following code.
// Insert code here to check the user is logged in
// If the user is valid, execute the code below:
readfile("/usr/filestore/".$_GET['filename']);
?>
When someone wants to download a file, they would click a link something like:
Download file
You may also wish to look into functions such as:
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
You should use these to tell the browser what type of file it is receiving, and you can give it a filename as well, so when the user saves it to the hard drive, it is called "mydoc.doc" rather than "file.php".
That would work fine.
> For my sites, I just use a SESSION variable.
>
> When the user logs in, set a session and go the the next page.
>
> At the top of the protected page, check whether the SESSION variable
> is set, if not, redirect to the login page. If it is, display the
> page.
>
> I suddenly have a feeling this might not be safe, but it seems to
> work for me.
Surely anyone can still access files though? Sounds like that'd work fine for .php files, but not for things you want the user to download or images or whatever...
If I only allow my IP won't I be the only one allowed to download it (and only from my own IP)...?
When the user logs in, set a session and go the the next page.
At the top of the protected page, check whether the SESSION variable is set, if not, redirect to the login page. If it is, display the page.
I suddenly have a feeling this might not be safe, but it seems to work for me.