替换的.htaccess弹出框与HTML表单? [英] Replace Htaccess popup box with a html form?
问题描述
我有密码保护的目录上使用htaccess的我的网站。当我输入的URL文件夹我得到一个简单的弹出框,我可以输入我的信息。一切都很好。但我真正想做的事,我有一个HTML / PHP / MySQL的形式,您可以登录,而不是一个弹出框。有没有办法做到这一点? 注:我要保护的目录有数百个文件
I have password-protected a directory on my website using htaccess. When I type in the URL to the folder I get a simple popup box where I can type in my info. All is fine. But what I really want to do i have a html/php/mySQL form where you can log in, instead of a popup box. Is there any way to do this? NOTE: The directory i want to protect has hundreds of files.
我知道如何做一个表单,查询数据库,我只是想用html表单代替弹出。
I know how to make a form, query a database, i just want to replace the popup with a html form.
推荐答案
一种可能的方法... 的
假设你要保护的目录下的保护。
Say you want to protect the directory "protected".
使用的.htaccess
,限制所有访问该目录内放
Using .htaccess
, limit all access to this directory by putting
Options -Indexes
# Block External Access
deny from all
在保护目录中的的.htaccess
文件。
接下来,使用一个重写规则来捕获所有的URL将在受保护的目录在你的主的.htaccess
文件。例如:
Next, use a RewriteRule to catch all URL's going to the "protected" directory in your main .htaccess
file. For example:
RewriteEngine on
RewriteRule ^protected/(.*) accessprotected.php?url=$1
通常情况下,重写规则应该抓住所有的URL将在受保护的目录,并将其传输到accessprotected.php页。
Normally, the RewriteRule should catch all URL's going to the "protected" directory and transmit them to the accessprotected.php-page.
在accessprotected.php页,检查登录状态。
On the accessprotected.php-page, check for login-status.
if (isset($_SESSION['LoggedIn'])) { // or something like this
/*
Here, you should check what file type is being
requested and handle this properly.
*/
} else {
// put code for login form here
}
这篇关于替换的.htaccess弹出框与HTML表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!