简体   繁体   English

如何使用密码保护某些HTML页面?

[英]How can I secure certain HTML pages with a password?

I like to create basic HTML websites. 我喜欢创建基本的HTML网站。 I know nothing about PHP, JavaScript, or any of that stuff. 我对PHP,JavaScript或其他任何东西一无所知。 I wanted to make a special page that when you access it, it will prompt you a username and password, and will only grant access if this is correct. 我想制作一个特殊的页面,当您访问它时,它将提示您一个用户名和密码,并且仅在正确的情况下才授予访问权限。

I have tried with the .htpasswd file, but I don't understand anything at all. 我已经尝试过.htpasswd文件,但是我什么都不懂。 I also would want to try either a login form, or a simple passcode and IP check, but I can't make one because I have no knowledge in dynamic website languages. 我也想尝试登录表单,或者简单的密码和IP检查,但是我做不到,因为我不了解动态网站语言。 Any tips? 有小费吗?

Your best bet is to persist with the .htpasswd solution - it is by far the simplest solution. 最好的选择是坚持使用.htpasswd解决方案-这是迄今为止最简单的解决方案。 You may not need to edit the actual .htpasswd and .htaccess files yourself - you may be able to use your hosting providers tools to 'secure a folder' or page. 您可能不需要自己编辑实际的.htpasswd和.htaccess文件-您可以使用托管服务提供商的工具来“保护文件夹”或页面。 Most hosting providers provide some gui tools to create users/passwords for access to a specific directory. 大多数托管服务提供商都提供一些gui工具来创建用于访问特定目录的用户/密码。 For instance you can find godaddy's documentation here: https://support.godaddy.com/help/article/4057/password-protecting-a-directory-in-your-shared-hosting-account?countrysite=ca 例如,您可以在这里找到godaddy的文档: https : //support.godaddy.com/help/article/4057/password-protecting-a-directory-in-your-shared-hosting-account? countrysite =ca

If your service provider doesn't have suitable tools, try this: http://www.htaccesstools.com/articles/password-protection/ 如果您的服务提供商没有合适的工具,请尝试以下操作: http : //www.htaccesstools.com/articles/password-protection/

You are going to need to learn a server side scripting languages. 您将需要学习服务器端脚本语言。 Go to w3school.Com and learn php Or c#. 转到w3school.Com并学习php或c#。 Creating a login form is a little more involved than what you think. 创建登录表单比您想象的要复杂得多。 You are going to need a database scheme with tables for users and passwords. 您将需要一个数据库方案,其中包含用于用户和密码的表。 You need to decide if you want to use cookies, sessions or a combination of both. 您需要确定是否要使用Cookie,会话或两者结合使用。 Once you have what you need you need to create a request for connection to the database and query for what ever login credentials you want. 拥有所需资源后,您需要创建一个连接数据库的请求,并查询所需的登录凭据。 The database will either answer with an ok or fail and your user is verified. 数据库将以“正常”回答,否则将失败,并且您的用户已通过验证。 Now you will create a cookie for information that you can check on every page to make sure the user is allowed to view the pages. 现在,您将创建一个cookie,以获取可在每个页面上检查的信息,以确保允许用户查看页面。

To make things simple learn a server language and learn to run queries from it. 为使事情变得简单,请学习服务器语言并学习从中运行查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM