简体   繁体   English

对非敏感链接的简单密码保护

[英]Simple password protection for non-sensitive links

I've been looking at password protection for HTML and most of the protection listed appears to be overkill for my needs. 我一直在寻找HTML的密码保护,列出的大多数保护似乎对我的需求来说太过分了。

I just want to have some portfolio images (nothing that needs to be private and it doesn't matter if any advanced programmer or someone that knows how to open the code can get into it because nothing is sensitive), I just don't want the average user to access certain areas of site and only allow someone who I give the password (for example on my business card.) 我只想要一些投资组合图像(没有什么需要是私有的,如果任何高级程序员或知道如何打开代码的人都可以进入它,因为没有什么是敏感的,这无关紧要),我只是不想要普通用户访问网站的某些区域,只允许我提供密码的人(例如在我的名片上)。

Does anyone have any suggestions or direction I should look? 有没有人有任何建议或方向我应该看?

Use javascript in your main page, something like this: 在您的主页面中使用javascript,如下所示:

<body>
Enter password: <input id='password' type='text'  />
<a href="your_image_portfolio.html" onclick="javascript:return validatePass()">enter your password and click this</a>
<script>
function validatePass(){
    if(document.getElementById('password').value == 'yourBussinessCardPassword'){
        return true;
    }else{
        alert('wrong password!!');
        return false;
    }
}
</script>
</body>

It's very insecure, but it will do what you want for non technical users... 这是非常不安全的,但它会为非技术用户做你想要的......

As said above, HTML doesn't support password protection directly. 如上所述,HTML不直接支持密码保护。 You can do this with PHP: create a form to enter a password that sends data to a PHP script. 您可以使用PHP执行此操作:创建表单以输入将数据发送到PHP脚本的密码。 Use an if statement at the beginning of the PHP script that checs whether the submitted data matches your password. 在PHP脚本的开头使用if语句来判断提交的数据是否与您的密码匹配。 If it doesn't, redirect/include some sort of error page. 如果没有,重定向/包含某种错误页面。 If it does, have it load the rest of the gallery from inside the if statement. 如果是,请从if语句中加载库的其余部分。

<?php

if ($_POST["password"] == 12345) {
page goes here
}
else {
include 'errorpage'
?>
    <script type="text/JavaScript">

    function Sinfo()
    {

        var info = document.getElementById("info").value; //Getting the value in the Text Area
        var help = "Hello"; // setting the value for the password 

            if(info==help){ // checking to see if info is equal to help

            document.write("Correct Password"); // writing correct password if correct


    }
        else{

        document.write("Wrong Password"); // writing the wrong password if wrong

        }

    }

    </script>

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

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