Home > CMS Tutorial > PHPCMS > body text

phpcms v9 determines whether the user is logged in

藏色散人
Release: 2020-02-03 10:50:13
Original
2036 people have browsed it

phpcms v9 determines whether the user is logged in

#phpcms v9 determines whether the user is logged in? How does phpcms V9 determine whether the user is logged in and the label writing problem after login

First get the userid

{php$userid=param::get_cookie('_userid');}
Copy after login

and then determine whether it is empty

{if $userid }. . . Write the code after logging in here. . . {else}. . . Write the code after logging in here. . . {/if}

Done.

If you want to expand more functions, such as adding the function of viewing contact information after logging in, we need to declare a variable to control the return page after logging in.

$forward = trim($url);
Copy after login

Code when not logged in

Log in to view contact information

Note that the link address must have the parameter forward={urlencode($url)} so that the user can successfully log in Return to previous content page.

Complete code

{php$userid=param::get_cookie('_userid');$forward=trim($url);}
{if$userid}
Copy after login

Content after login

{else}
<<span style="">ahref="{APP_PATH}index.php?m=member&c=index&a=login&forward={urlencode($url)}&siteid={$siteid}"target="_top">
Copy after login

Log in to view contact information

<<span style="">/a>
{/if}
Copy after login

But if we want to be on the homepage If you want to implement it, this method will not work, because the homepage is static, we can achieve it by writing a method.

Open /phpcms/modules/content/index.php and add

//首页用户登录
publicfunctionmember(){
$_username=param::get_cookie(&#39;_username&#39;);
$_userid=param::get_cookie(&#39;_userid&#39;);
$siteid=isset($_GET[&#39;siteid&#39;])?intval($_GET[&#39;siteid&#39;]):&#39;&#39;;
//定义站点id常量
if(!defined(&#39;SITEID&#39;)){
  define(&#39;SITEID&#39;,$siteid);
}
$snda_enable=pc_base::load_config(&#39;system&#39;,&#39;snda_enable&#39;);
includetemplate(&#39;member&#39;,&#39;afterlogin&#39;);
}
Copy after login

The method name can be defined by yourself according to the actual situation. Then add

< script type="text/javascript">document.write(&#39;< iframe src="{APP_PATH}index.php?m=content&c=index&a=member&forward=&#39;+encodeURIComponent(location.href)+&#39;&siteid={get_siteid()}" allowTransparency="true"  width="125" height="98" frameborder="0" scrolling="no">< /iframe>&#39;)< /script>
Copy after login

PHP Chinese website in the position that needs to be displayed on the home page template. A large number of free PHPCMS tutorials are welcome to learn online!

The above is the detailed content of phpcms v9 determines whether the user is logged in. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template