如何实现独立页面加密访问

如何实现独立页面加密访问

<?php
/**
 * 加密模板
 *
 * @package custom
 */
 ; ?>
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<div class="col-mb-12 col-8" id="main" role="main">
    <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
        <h1 class="post-title" itemprop="name headline"><a itemtype="url" href="<?php $this->permalink() ?>"><?php $this->title() ?></a></h1>
        <div class="post-content" itemprop="articleBody">
<?php 
$password = "1234"; // 这里是密码 
$p = ""; 
if(isset($_COOKIE["isview"]) and $_COOKIE["isview"] == $password){ 
$isview = true; 
}else{ 
if(isset($_POST["pwd"])){ 
if($_POST["pwd"] == $password){ 
setcookie("isview",$_POST["pwd"],time()+3600*3); 
$isview = true; 
}else{ 
$p = (empty($_POST["pwd"])) ? "对不起,您输入的密码错误!" : "对不起,您输入的密码错误!"; 
} 
}else{ 
$isview = false; 
$p = "请输入密码访问:"; 
} 
} 
 
if(@$isview){ ?> 




            <?php $this->content(); ?><?php }else{ ?>
         <form class="protected" action="?yes" method="post"><p class="word"><?php echo $p; ?></p>
<p>
<input type="password" class="text" name="pwd" />
<input type="submit" class="submit" value="提交" />
</p>
</form> <?php 
} ?> 
        </div>
    </article>





    <?php $this->need('comments.php'); ?>
</div><!-- end #main-->
<?php $this->need('sidebar.php'); ?>
<?php $this->need('footer.php'); ?>

相关文章

发表新评论