### [phpcms v9判断用户是否登录](https://www.prosaas.cn/article/6355) **Published:** 2020-02-03T02:50:13 **Author:** 5201314 **Excerpt:** phpcms v9判断用户是否登录?phpcms V9如何判断用户是否登录以及登陆后的标签写法问题首先要获取u… ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212124944902.jpg) **phpcms v9判断用户是否登录?phpcms V9如何判断用户是否登录以及登陆后的标签写法问题** 首先要获取userid {php$userid=param::get\_cookie('\_userid');} 然后再判断是否为空 {if $userid}。。。这里写已经登录之后的代码。。。{else}。。。这里写已经登录之后的代码。。。{/if} 搞定。 如果想要扩展更多的功能,比如内容增加 登录后查看联系方式 的功能,此时我们需要声明一个变量,用来控制登录后的返回页面。 $forward = trim($url); 未登录时的代码 登录查看联系方式 注意链接地址里面要有参数forward={urlencode($url)} 这样用户登录后才能成功返回到之前的内容页面。 **完整的代码** {php$userid=param::get\_cookie('\_userid');$forward=trim($url);} {if$userid} 登录后的内容 {else} <ahref="{APP\_PATH}index.php?m=member&c=index&a=login&forward={urlencode($url)}&siteid={$siteid}"target="\_top"> 登录查看联系方式 </a> {/if} 但是如果我们想在首页想要实现的话用这样的方法就行不通了,因为首页为静态,我们可以通过写一个方法来实现。 打开/phpcms/modules/content/index.php 增加 //首页用户登录 publicfunctionmember(){ $\_username=param::get\_cookie('\_username'); $\_userid=param::get\_cookie('\_userid'); $siteid=isset($\_GET\['siteid'\])?intval($\_GET\['siteid'\]):''; //定义站点id常量 if(!defined('SITEID')){ define('SITEID',$siteid); } $snda\_enable=pc\_base::load\_config('system','snda\_enable'); includetemplate('member','afterlogin'); } 方法名可以自己根据实际情况来定义。然后在首页模板上需要显示的位置增加 < script type="text/javascript">document.write('< iframe src="{APP\_PATH}index.php?m=content&c=index&a=member&forward='+encodeURIComponent(location.href)+'&siteid={get\_siteid()}" allowTransparency="true" width="125" height="98" frameborder="0" scrolling="no">< /iframe>')< /script> PHP中文网,大量的免费PHPCMS教程,欢迎在线学习! 以上就是phpcms v9判断用户是否登录的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** if, php, PHPCMS **Categories:** PHPCMS ---