我使用PHP脚本(AdLinkFly - 货币化网址缩短器)
我想根据登录用户显示不同的菜单。如果用户是客户端,则显示Manage Account和LogOut,否则显示Sing-Up和Sing-In。
这是主页http://adshort.ga 这是代码" front.ctp" :
<html lang="<?= locale_get_primary_language(null) ?>">
<head>
<?= $this->element('front_head'); ?>
</head>
<body class="<?= ($this->request->here == $this->request->webroot) ? 'home' : 'inner-page' ?>">
<?= get_option('after_body_tag_code'); ?>
<!-- Navigation -->
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1">
<span class="sr-only"><?= __('Toggle navigation') ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<?php
$logo = get_logo();
$class = '';
if ($logo['type'] == 'image') {
$class = 'logo-image';
}
?>
<a class="navbar-brand <?= $class ?>" href="<?= $this->Url->build('/'); ?>"><?= $logo['content'] ?></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="<?= $this->Url->build('/'); ?>"><?= __('Home') ?></a>
</li>
<?php if (get_option('enable_advertising', 'yes') == 'yes') : ?>
<li>
<a href="<?= $this->Url->build('/advertising-rates'); ?>"><?= __('Advertising') ?></a>
</li>
<?php endif; ?>
<li>
<a href="<?= $this->Url->build('/payout-rates'); ?>"><?= __('Payout Rates') ?></a>
</li>
<?php if ((bool)get_option('blog_enable', false)) : ?>
<li>
<a href="<?= $this->Url->build('/blog'); ?>"><?= __('Blog') ?></a>
</li>
<?php endif; ?>
<li>
<a href="<?= $this->Url->build('/auth/signin'); ?>"><?= __('Sign in') ?></a>
</li>
<li>
<a href="<?= $this->Url->build('/auth/signUP'); ?>"><?= __('Sign Up') ?></a>
</li>
<li>
<a href="<?= $this->Url->build('/member/dashboard'); ?>"><?= __('Dashboard') ?></a>
</li>
<?php if (count(get_site_languages(true)) > 1) : ?>
<li class="dropdown language-selector">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false"><i class="fa fa-language"></i> <span class="caret"></span></a>
<ul class="dropdown-menu">
<?php foreach (get_site_languages(true) as $lang) : ?>
<li>
<?= $this->Html->link(
locale_get_display_name($lang, $lang),
'/' . $this->request->url . '?lang=' . $lang
); ?>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endif; ?>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<?= $this->Flash->render() ?>
<?= $this->fetch('content') ?>
<?= $this->element('front_footer'); ?>
</body>
</html>
&#13;
我不是PHP的专家我会很感激有人可以帮助我
答案 0 :(得分:-1)
当用户登录时,启动session session_start()
,然后在存储脚本可识别的值时添加到$_SESSION
变量,例如:{{1}然后在主文件中,您可以添加:
$_SESSION['userLogged'] = true;
想象一下,您希望显示带有文本&#34; Hello world!&#34;的 session_start();
if($_SESSION['userLogged'] == true) {
//Display here the HTML with echo function
} else {
//Load the normal page
}
标记,然后您必须转到html文件,找到您希望代码所在的标记执行,然后执行以下代码。例如:
<p>