473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

preventing external access to directory

I have a directory with files (of various formats) contained within a
website which uses PHP to control user access via session variables. I would
like to protect the directory from direct external linking (e.g. prevent
people typing "http://www.mysite.com/protected-directory/file.doc" into the
address bar for example), so that users must log on to the website first to
gain access to them. Currently, I've used a .htaccess file, but this
requires the users to enter an additional password, which is a hassle. I'd
like to be able to pass the htaccess username and password directly to the
server using a script embedded in a PHP file, but since Microsoft have
prevented the use of username/password combinations within the URL in IE,
this method is no longer viable. Can anyone suggest an alternative solution
or a way around the http authentication problem?

Cheers,
J

--
-----Personal Disclaimer--------
Thanks to the explosion of abuse of email on the 'net,
I have taken to adding this disclaimer to all email. It's
not a legal statement, just a form of insurance. If you
get a message that appears to be from me, but it doesn't
have this disclaimer at the bottom, please treat it as
spam, as it has not originated from me.
-----End Disclaimer------

Jul 17 '05 #1
5 2409
J C-W <j@no.spam.here.com> wrote:
I have a directory with files (of various formats) contained within a
website which uses PHP to control user access via session variables. I would
like to protect the directory from direct external linking (e.g. prevent
people typing "http://www.mysite.com/protected-directory/file.doc" into the
address bar for example), so that users must log on to the website first to
gain access to them. Currently, I've used a .htaccess file, but this

[...]

So you are using apache:
- move file out of the documentroot (or into a directory protected by
.htaccess)
- add a 404 handler to the protected-directory which points to a php
script which uses your normal authentication methods
- have this script serve the "protected" files, you'll need to set the
correct mime-type and http-status (eg 200) if the actual file can be
found

--

Daniel Tryba

Jul 17 '05 #2
J C-W wrote:
[snip]
but since Microsoft have
prevented the use of username/password combinations within the URL in IE,
this method is no longer viable.

<quote src="http://support.microsoft.com/kb/834489">

How to disable the new default behavior for handling user information in
HTTP or HTTPS URLs

To disable the new default behavior in Windows Explorer and Internet
Explorer, create iexplore.exe and explorer.exe DWORD values in one of
the following registry keys and set their value data to 0.

.. For all users of the program, set the value in the following
registry key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME _PASSWORD_DISABLE

.. For the current user of the program only, set the value in the
following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME _PASSWORD_DISABLE

</quote>

I haven't tested this.

Can anyone suggest an alternative solution
or a way around the http authentication problem?


Maybe cookies? as recommended by the site above?
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #3
Thanks for the suggestion - this is kind of what I've done in the end - all
hyperlinks to protected files are served by a script which checks for site
authentication before delivering the file - found the following useful
script on another forum:

//authentication checking script first, then...
$dir = $_SERVER['C_DOCUMENT_ROOT'].'/protected/';
$file = $dir.basename($_REQUEST['dl']);
if (isset($_REQUEST['dl']) && file_exists($file)) {
header('Content-type: application/force-download');
header('Content-Transfer-Encoding: Binary');
header('Content-length: '.filesize($file));
header('Content-disposition: attachment; filename='.basename($file));
readfile($file);
} else {
echo 'Either there was no file with that name for download, there was an
error, or your login session expired.';
}

Thus, if anyone tries to access the protected directory directly, a prompt
for a password is given, which should prevent all but the most tenacious
hacker (there's nothing worth that much effort in the directory anyway), and
if any registered user tries to copy the links to the files (in the form
http://www.mydomain.com/dl.php?dl=filename) and pass them onto a
non-registered user, entering the url into the browser will forward them to
the log in page.

I will add the 404 handler as per your suggestion too, just as an extra
safeguard.

J
--
-----Personal Disclaimer--------
Thanks to the explosion of abuse of email on the 'net,
I have taken to adding this disclaimer to all email. It's
not a legal statement, just a form of insurance. If you
get a message that appears to be from me, but it doesn't
have this disclaimer at the bottom, please treat it as
spam, as it has not originated from me.
-----End Disclaimer------
"Daniel Tryba" <ne****************@canopus.nl> wrote in message
news:cl**********@news.tue.nl...

So you are using apache:
- move file out of the documentroot (or into a directory protected by
.htaccess)
- add a 404 handler to the protected-directory which points to a php
script which uses your normal authentication methods
- have this script serve the "protected" files, you'll need to set the
correct mime-type and http-status (eg 200) if the actual file can be
found

--

Daniel Tryba

Jul 17 '05 #4
.oO(J C-W)
but since Microsoft have
prevented the use of username/password combinations within the URL in IE,
this method is no longer viable.


It was never allowed by any standard in HTTP URLs.

Micha
Jul 17 '05 #5
"Daniel Tryba" <ne****************@canopus.nl> wrote in message
news:cl**********@news.tue.nl...
So you are using apache:
- move file out of the documentroot (or into a directory protected by
.htaccess)
- add a 404 handler to the protected-directory which points to a php
script which uses your normal authentication methods
- have this script serve the "protected" files, you'll need to set the
correct mime-type and http-status (eg 200) if the actual file can be
found


Using PHP to serve file download isn't really the best solution, since you
lose the web server's cache handling and partial retrieval capability
(doable but tricky to implement yourself).

A cleaner way to protect files would be to use Apache rewrite. In give
someone access, you add an entry into a rewrite map with the PHP session ID
as the key. A rewriteCond statement would then extract the PHP session id
from HTTP_COOKIE, while a second rewriteCond would check whether the id is
in the rewrite map. If it's not, then the request is rewritten to an access
denied page.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Erohsik | last post by:
I am using external tables to load data from the data file. But the log files are getting created in the datafile's directory (because of CREATE OR REPLACE DIRECTORY ...) But I want those log...
1
by: gajaya1 | last post by:
I only find information connecting Oracle external tables to data files. But I dont want to transfer data to files instead I want directly transfer data to oracle from Access. I do not know how to...
8
by: Scott Allen | last post by:
Hello, I'm new to C++ development and I'm trying out figure out the cause of an 'unresolved external symbol' error that I'm receiving when compiling. Here is some history on what I'm doing: I...
1
by: Eike | last post by:
Hi, I am unable to delete a subfolder that I have created programatically. I am using a modification of the apiSHFileOperation by Dev Ashish (http://www.mvps.org/access/api/api0026.htm) to copy...
10
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login...
2
by: Lance | last post by:
I need to prevent files from being manipulated (e.g., renamed or moved) by external applications (e.g., Windows Explorer) while my app is working with the files. The length of time that my app works...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips for using External tables. USING EXTERNAL TABLE ======================= 1.THE TABLE POINTS TO EXTERNAL FILE. IF DATA IS ALTERED IN THE EXTERNAL FILE,DATA...
3
by: tundal45 | last post by:
Hey Guys, I am trying to automate the process of loading data in our oracle server. As a part of that process, I am working on a perl script that loads external tables from data files. What I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.