我正在尝试使用密码保护我正在使用的CMS的页面(couchcms(。从"合同.php"页面生成的所有页面都有一个唯一的 ID 和 URL。
我想做的是,如果您访问这些页面之一,则在页面加载时弹出一个提示窗口,如果您输入的内容与您访问过的 URL 的合同 ID 不匹配,它将不允许用户访问该页面。
如果 ID 匹配,则可以查看访问的页面。
例如:
合约 #334455 具有以下网址: example.com/contract/25348764329871098723498
如果我单击该链接,我只会看到一个空白页面,并会看到一个提示窗口。我必须在字段中输入334455才能解锁页面。如果不是正确的 ID(与当前 URL 不匹配(,它应该显示一条消息阻止页面。
我尝试了这样的东西,但这还不够安全,因为您可以在源代码中看到它,并且它会重定向到同一页面,因此它会创建一个循环并始终要求输入密码。我需要它来解锁页面,而无需重定向:
<SCRIPT>
function passwordCheck(){
var password = prompt("Please enter the password.");
if (password==="<cms:show my_uid/>"){
window.location="<cms:show k_page_link/>";
} else{
while(password !=="<cms:show my_uid/>"){
password = prompt("Please enter the password.");
}
}
}
window.onload=passwordCheck;
</SCRIPT>
以下是有关所用变量的一些详细信息:
<cms:show my_uid/> = The generated ID for the page
<cms:show k_page_link/> = The generated URL for the page
这些变量因每个页面而异。
有什么解决方案会更安全并且像我描述的那样工作吗? 多谢
这是你可以做的事情。 当然,它不是最安全的,但这是对源代码隐藏的简单逻辑:
**<?php
//All the verification stuff
$password = "YOURPASSWORD";
function load_verify () {
echo "<input type='password' name='txt_check' value='' style=' width: 300px; height: 30px; border-radius: 5px;' /> <br> ";
echo "<input type='submit' name='btn_check' value='Verify' style=' width: 300px;' /> <br> <br> ";
}
//check the password
if (isset($_POST['btn_check'])) {
if ($password === $_POST['txt_check']){
$_SESSION['is_verified'] = 1 ;
}else {
echo "Please Try Again <br>" ;
$_SESSION['is_verified'] = 0 ;
}
}
$test = (isset($_SESSION['is_verified']))? 1:0 ;
//if password fails we reload the verify form if not we load the form and hide the verify
if ( $test === 1 && $_SESSION['is_verified'] === 1 ) {
load_form();
$_SESSION['is_verified'] = 1 ;
} else {
load_verify();
}
?>