[英]Using php or javascript to log a user into a directory protected with Apache Basic Authentication (htaccess/htpasswd)
Is it possible to use PHP or Javascript to login to a directory protected with Apache Basic Authentication? 是否可以使用PHP或Javascript登录受Apache基本身份验证保护的目录?
A simple example: 一个简单的例子:
Is this possible? 这可能吗? If so, how can I achieve this?
如果是这样,我怎么能做到这一点?
Update: Do to my client's implementation requirements, I can not use a php based authentication system. 更新:对我的客户端的实现要求,我不能使用基于PHP的身份验证系统。 It needs to be apache authentication.
它需要是apache身份验证。
It is possible to use 可以使用
header("Location: http://$username:$password@myurl.com/protected");
Although, I would advise against it, and use a php based authentication mentioned above without the Apache basic authentication. 虽然,我会建议反对它,并使用上面提到的基于PHP的身份验证,而不使用Apache基本身份验证。
My understanding about the basic authentication with apache is that it is, by definition, basic. 我对apache基本身份验证的理解是,根据定义,它是基本的。 If you are willing to work with php and mysql, you can build a simple login system that would suit your needs.
如果您愿意使用php和mysql,您可以构建一个适合您需求的简单登录系统。 Just check a username and password against its counterparts in a mysql database (of course hash the password with md5, or sha256), and if it is correct, set a session variable saying so.
只需检查mysql数据库中对应的用户名和密码(当然使用md5或sha256哈希密码),如果正确,请设置一个会话变量。 Check that variable on each page that needs authentication, and redirect if it isn't set/set to false.
检查每个需要身份验证的页面上的变量,如果未设置/设置为false,则重定向。
Here is a good example: http://progtuts.info/92/login-system/ 这是一个很好的例子: http : //progtuts.info/92/login-system/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.