security - Using PHP/Apache to restrict access to static files (html, css, img, etc) -


Indicates that you have a lot of HTML, CSS, JS, IMG and etc. files are in a directory on your server. However, in the internet-land a user can fully access the files by typing as URL:

Now, what if you want to be able to load those files only to authorized users ? For this example, say that your users first log in from the URL:

How will you allow the user to view the index.html file (or "static-file" "), But restricts the rest of the file?

I have come away with two possible solutions in this way:

Solution 1
Adhere to the .htaccess file under "static-file":

  option + follow on follow link rewrite engine Graphite ^ (. *) $ ../authorize.php?file=$1 [NC]  

and then in authorize.php ...

  If (isLoggedInUser ()) readfile ('static-files /'. $ _ Request ['file']); Second echo 'reject';  

This authorize.php file is completely simplified

Deny order, allow denial of all from 000.000.000.000 Allow

and then add my login page Awareness is the .htaccess file that logs the IP address for each user. Obviously this will also require the regularity of any kind of cleanliness to purify the old or now use IP.


I worry that my first solution can be quite expensive on the server because the number of users and files is increasing. I think my second solution would be very less expensive, but due to IP spoofing and etc. it is also less secure. I also worry that writing these IP addresses in the HTACAC file can be an obstacle to the application if there are many users

Which of these solutions looks better, and why? Alternatively, can you think of a completely different solution which would be better than these two?

Consider using a PHP loader to handle authentication, and then you can access your required files return back. For example & lt; Img src = 'picture.jpg' / & gt; Instead of & lt; Img src = 'load_image.php? Image = picture.jpg '/ & gt; .

Your image loader can verify session, check credentials, etc. and then decide whether to return the requested file back to the browser. This will allow you to store all your secure files outside the Web secure route so that no one can just go to WGET or browse 'accidentally' on them.

Just return the right header in PHP and something like readfile () in PHP and he will return the browser's file content.

EDIT: I am creating this time that the system uses this method to load JavaScript, images, and video but css we are not very worried about securing.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -