Jump to content

how to restrict access to directory?


jaydeesmalls

Recommended Posts

Hi everyone,

 

I have a part on my site that I want to restrict access to only registered users.  I have a register page and a log in page, but how do I restrict pages after that.  Currently, anyone who knows the url of the pages that I want to restrict can just type it in and access, and I want to prevent that.

 

Thank you very much for the input.

Link to comment
https://forums.phpfreaks.com/topic/108535-how-to-restrict-access-to-directory/
Share on other sites

Can you post your login page php source? We need to know what your session username is registered as.

 

<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>

 

Putting that at the top of all your files should work, providing you change myusername with your registered username variable.

 

However, this only protects certain files, if you wish to protect an entire directory, I'd look into .htaccess:

http://www.google.com/search?q=.htaccess

if it's php, you need user access restrictions on it (I use session variables to handle all that). You can find quite a few tutorials already in these forums by searching for "Sessions".  I'm more than glad to assist further, but to code it from scratch, that would take more time than I have right now (at work), but I'm sure some people here would be glad to offer some form of help.

Just know that sessions will just stop people from running .php pages in those directories.  If there are other things in there like .zip files, it won't stop them.  As stated above, you would need to use .htaccess for directory protection.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.