#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');}
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);
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}
Content after login
{else} <<span >ahref="{APP_PATH}index.php?m=member&c=index&a=login&forward={urlencode($url)}&siteid={$siteid}"target="_top">
Log in to view contact information
<<span >/a> {/if}
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('_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'); }
The method name can be defined by yourself according to the actual situation. Then add
< 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 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
