Typecho根据访客记录自动显示隐藏账号cookies信息

Typecho根据访客记录自动显示隐藏账号cookies信息

typecho内置有这方面的功能,也就是<?php $this->remember(''); ?>

<?php $this->remember('author'); ?> = 账号信息

<?php $this->remember('mail'); ?> = 邮件信息

也就是typecho提交信息后会留下cookies值,<?php $this->remember(''); ?>就是用来获取cookies的账号信息

那么,也就可以这样

<?php if($this->user->hasLogin()): ?>
                    <div class="hasLogin">
                            <?php $email=$this->user->mail; $imgUrl = getGravatar($email);echo '<img src="'.$imgUrl.'" width="22px" height="22px" class="avatar hasLogin-author" >'; ?><?php $this->user->screenName(); ?>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout">退出 &raquo;</a>
                    </div>    
                        <?php else: ?>
               <?php if($this->remember('author',true) != "" && $this->remember('mail',true) != "") : ?>
               <div class="hasLogin comm_on" id="comm_on">
                        <?php $this->remember('author'); ?>. <a href="javascript:;" onclick="bian()" title="Logout" >编辑资料? &raquo;</a>
<script>function bian()
{ var oBox = document.getElementById("comm_off"); var oBox1 = document.getElementById("comm_on"); oBox.style.display= "block"; oBox1.style.display= "none";}</script>
               </div>    
               <ul class="ident" id="comm_off">
                    <li>
                        <input type="text" name="author" placeholder="昵称*" value="<?php $this->remember('author'); ?>">
                    </li>
                    <li>
                        <input type="mail" name="mail" placeholder="邮件*" value="<?php $this->remember('mail'); ?>">
                    </li>                   
                </ul>
               <?php else : ?>
                <ul class="ident">
                    <li>
                        <input type="text" name="author" placeholder="昵称*" value="<?php $this->remember('author'); ?>">
                    </li>
                    <li>
                        <input type="mail" name="mail" placeholder="邮件*" value="<?php $this->remember('mail'); ?>">
                    </li>                   
                </ul>
             <?php endif; ?><?php endif ; ?>  

以上的大概思路是

1,判断是否注册用户,如果是注册用户,直接显示账号信息

2,只是游客用户,判断用户是否有过cookies的信息,如果有,则不需要填入昵称和邮件,如果用户想改变昵称邮箱,可以直接点击编辑资料,进行修改

3,如果是新的游客,没有留言回复过,则显示正常的初步昵称和邮件地址

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索