菜鸟站长
个人博客主题模板、应用插件、功能开发技术资源聚合分享网站

Typecho 自定义密码保护文章的状态码和密码输入框

发布者:菜鸟站长-投稿  发布日期:2024-08-13  更新日期:2024-08-25  人气指数:46

Typecho 的 密码保护 文章在没有输入密码的情况下会返回403代码,要是 Nginx 自定义 了 403 验证码就会导致无输入密码查看文章

修改functions.php

function themeInit($self) {
    if ($self->hidden) { // 密码保护 hidden 为 true
        $self->response->setStatus(200);
    }
}

修改密码输入框

修改post.php,把<?php $this->content(); ?>修改为如下

<?php if ($this->hidden): ?>
    <div class="text-center mx-auto" style="max-width: 420px;">
        <form
            action="<?php echo Helper::Security()->getTokenUrl($this->permalink); ?>"
            method="post">
            <div class="input-group">
                <input type="password" name="protectPassword" class="form-control"
                       placeholder="<?php _e("输入密码打开新世界大门"); ?>"
                       aria-label="<?php _e("输入密码打开新世界大门"); ?>">
                <input type="hidden" name="protectCID" value="<?php $this->cid(); ?>"/>
                <button class="btn btn-primary" type="submit"><?php _e("确定"); ?></button>
            </div>
        </form>
    </div>
<?php else: ?>
    <?php $this->content(); ?>
<?php endif; ?>
本文检索关键词:功能代码 , typecho教程 , 主题开发

菜鸟站长推荐教程



添加新评论 »

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png