特定页面的密码保护
我一直在用 PHP 制作一个教育网站,并且我决定对公众的页面进行密码保护,除非他们登录(在本例中是学生)。
涵盖的科目是 GCSE 数学、英语和历史,我想通过密码锁定页面。
我查看的选项是:
.htpassword = 此处不相关
各种密码保护脚本 = 他们可以锁定页面,但人们可以查看所有页面 - 没有多大用处,当我希望人们输入不同网页的密码不同(例如,您访问GCSE英语文献页面,登录后使用单独的密码查看,您访问GCSE数学代数页面,登录后输入不同的密码查看)它。)
用户注册不是问题,因为他们是学生,我正在创建用户和密码 - 防止无用的注册等。
主要问题不是如何进行密码保护,除了用户登录之外,如何在每个受保护的页面上使用不同的密码,那么您有什么建议呢?
我已经完成了研究,但不确定下一步该做什么,那么我应该从哪里开始?
抱歉,如果它看起来很复杂,只是这个问题对我来说相当重要,而且我在网上找到的脚本似乎都不适合这个问题,而且我的 PHP 编码技能对于初学者来说很有用,但在保护 PHP 文件的领域则不然。
(我曾考虑过 CMS,但由于该网站是从以前的 HTML 页面改编而来的 PHP 版本,因此对于它的目标受众来说没有意义 - 它是一个教育网站,而不是商业网站,而且该网站本身是不管怎样,将服务器转移到新的 Apache 上。)
I've been making an educational website in PHP, and I've decided to password-protect pages to the public unless they're signed in - in this case, students.
The subjects covered are GCSE Maths, English and History, and I want to lock the pages via password.
Options I looked at were:
.htpassword = Not relevant here
Various password protection scripts = they could lock the pages, but people could view all pages - not much use, when, say I want people to enter a DIFFERENT password for DIFFERENT webpages (e.g. you visit the page on GCSE English literature, you use a separate password once logged-in to view it, you visit the page on GCSE Maths algebra, you would enter a different password once logged-in to view it.)
User registration isn't an issue, as because they're students, I'm creating the users and passwords - preventing useless registrations etc.
It's not how to password-protect that's the main issue, it's how to use a different password on every protected page in addition to the user login, so what would you suggest?
I've done my research, but am not sure where to go next with this, so where should I progress from here?
Sorry if it seems complex, it's just this issue is fairly important for me and none of the scripts I found online seemed to fit this, and my PHP coding skills are good for a beginner, but not in the area of securing files in PHP.
(I'd considered a CMS but since the site is a PHP adaptation from former HTML pages, it didn't make sense for the audience it was aimed at - it is an educational site, not a business site, and the website itself is moving servers anyway to a new Apache one.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在实际注册用户时,为什么不授予用户权限而不是额外的密码呢?如果您为学生添加额外的材料,这将更加高效并为您的解决方案增加灵活性。
它只需要一个额外的数据库表来将您的用户链接到材料。
While actually registering your users, why not give your users permissions instead of extra passwords? That would be more efficient and add flexibility to your solution - in case you add extra material for your students.
It would only require an extra database table to link your users to the materials.
我能想到的最基本的事情就是创建一个包含页面、用户名和密码的数组的 PHP 文件。
然后检查您的页面。也许通过 $_GET 或使用 POST 制作一个简单的表单。
The most basic thing I can come up with, is just make a PHP file with arrays that contain pages, usernames and passwords.
And then check on your page for this. Maybe through $_GET or make a simple form with POST.
您可以使用
PHP
中的session
来完成此操作。这是会话的完整说明。但这里是您网站的代码:
您可以使用
MySql
在其中存储您的密码
和用户名
。或者可以在服务器中创建一个array
(用于存储数据)文件和一个login
(用于处理登录)文件。但我建议您为您的用户创建一个开发良好的基于用户的系统,并为注册用户提供一些特价优惠。
希望这有帮助。
You can do this with the
session
inPHP
. Here is a full explanation of session.But here is a code for your site :
And you can use
MySql
to store yourpasswords
andusername
in it. Or can just create anarray
(to store data) file and alogin
(to process login) file in your server.But I recommend you to create a well developed user based system for your users and give some specials offers for registered users.
Hope this helps.