php login script that also works on subdirectories?
I know it's quite easy to make a login sc开发者_如何转开发ript for one directory. However, how do you make it work recursively (subdirectories)?
Thanks!
You can go about this a couple different ways.
Your first option (and the most intuitive) is to simply include your authentication code (checking for session, etc.) in every page within the directory. This just means a lot of copy-pasting an include()
statement.
However, if you're looking to protect non-script content like images or other files, you can use Apache's mod_rewrite
to redirect any calls for files to a single PHP script that handles authentication. This is the more robust method and is widely used, but it has a small learning curve to work with mod_rewrite
.
精彩评论