Reputation: 746
I have an
http://example.com/DL/
directory with free access for anyone, now I wanna to deny access for unauthorized users so I writte very simple index.php with code
<?php
include('config.php');
session_start();
$result = (mysql_query("SELECT * FROM accounts WHERE hash='".$_SESSION['hash']."' ");
$row = mysql_fetch_array(result);
if($row['access']) {
return true;
} else {
header("location: /login.php");
}
?>
question: is there way to setup .htaccess to check if index.php returns true every time user request
http://example.com/DL/*
?
Upvotes: 0
Views: 255
Reputation: 7775
You can use mod_rewrite to make all requests be routed to index.php.
See this example.
This way you can utilize the Front Controller Pattern
Which basically means that index.php will be your router into the other parts of your code. This allows for the access control that you are looking for but also lets you have a good structure of the rest of your code.
Another recommendation is to only expose index.php in your web root and have the rest of your code outside of the publicly visible folder. This way you will also prevent someone from fetching all your code base when you forget to configure apache properly.
Upvotes: 1