用js实现时加密会被人看到,较不安全。用php+session等方式较安全。
<script type="text/javascript">
function password() {
var testV = 1;
var pass1 = prompt('请输入密码','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1 == "123") {//初始密码123
alert('密码正确');
break;
}
testV+=1;
var pass1 =
prompt('密码错误!请重新输入:');
}
if (pass1!="password" & testV ==3)
history.go(-1);
return " ";
}
document.write(password());
</script>
<!--下面添加你要显示的内容或者代码-->
<script type="text/javascript">
loopy()
function loopy() {
var sWord =""
while (sWord != "123") {//设置密码
sWord = prompt("输入正确密码才能登陆!")
}
alert("欢迎访问")
}
</script>
<!--下面添加你要显示的内容或者代码-->
<script type="text/javascript">
function password() {
var testV = 1;
var pass1 = prompt('请输入密码:','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1 == "123") {//设置密码
alert('口令正确,进行跳转');
window.location.href="https://xun.junbuhui.com/";//添加你要跳转的页面
break;
}
testV+=1;
var pass1 =
prompt('密码错误','');
}
if (pass1!="password" & testV ==3)
history.go(-1);
return " ";
}
document.write(password());
</script>
<?php
session_start();
$adminkey = "123";/*设置密码*/
if(@$_POST['password'] == $adminkey){
$_SESSION['login'] = md5($adminkey);
//header("location: " . $_SERVER['PHP_SELF'].'?action=normal');
}//if
if($_SERVER['QUERY_STRING'] == "logout"){
$_SESSION['login'] = "";
header("location: " . $_SERVER['PHP_SELF']);
exit();
}
$html_login = <<<EOF
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div{text-align:center; margin:0 auto;}
#loginform{width:230px;height:100px;background-color:#ffffff;box-shadow: 2px 2px 10px 1px #403f3f;}
</style>
</head>
<body>
<div id="loginform">
<div style="text-align:center; margin:260px auto 0px;">
<form action="" method="post">密码<input type="password" name="password" style="width:120px; margin-top: 35px;">
<input type="submit" value="登录" style="margin-left: 5px;">
</form>
</div>
</div>
</body>
</html>
EOF;
if(@$_SESSION['login'] != md5($adminkey)){
exit($html_login);
}
if(isset($_SESSION['login'])){
echo "显示成功";
}
?>