我已经创建了一个登录表单,我也有会话。这工作正常,你也可以看到我登录后可以看到更多按钮。我希望我的登录在右上角切换到用户名,在下拉菜单中我得到一个注销的红色按钮。我一直试图用按钮做一些编码...我<?php include 'buttons.php' ?>
。但我无法得到任何工作。
您在左侧看到的退出按钮正在运行,所以问题是更多,我怎样才能在下拉菜单中找到它?
的header.php
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<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>
<a class="navbar-brand topnav" href="index.php">Logo</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="#about">About</a>
</li>
<li>
<a href="#services">Services</a>
</li>
<li>
<a href="#contact">Contact</a>
</li>
<?php include 'buttons.php' ?>
<!-- Login Form -->
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><b>Login</b> <span class="caret"></span></a>
<ul id="login-dp" class="dropdown-menu">
<li>
<div class="row">
<div class="col-md-12">
Login via
<div class="social-buttons">
<a href="#" class="btn btn-fb"><i class="fa fa-facebook"></i> Facebook</a>
<a href="#" class="btn btn-tw"><i class="fa fa-twitter"></i> Twitter</a>
</div>
or
<form class="form" role="form" method="post" action="" accept-charset="UTF-8" id="login-nav">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" name="username" class="form-control" id="exampleInputEmail2" placeholder="Email address" required>
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword2">Password</label>
<input type="password" name="password" class="form-control" id="exampleInputPassword2" placeholder="Password" required>
<div class="help-block text-right"><a href="">Forget the password ?</a></div>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-block">Sign in</button>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> keep me logged-in
</label>
</div>
</form>
</div>
<div class="bottom text-center">
New here ? <a href="join.php"><b>Join Us</b></a>
</div>
</div>
</li>
</ul>
</li>
</ul>
<!-- /.Login Form -->
</div>
<!-- /.container -->
</nav>
profile.php
<body>
<?php require 'header.php' ?>
<br><br><br><br><br><br><br><br><br>
<div id="container">
<div class="topbar">
<h4 class="hello">Hello, <em><?php echo $_SESSION['username'];?>!</em>
<a href="logout.php" style="font-size:18px">Logout?</a>
<a href="test.php">test</a></h4>
</div>
</div>
</body>
session.php文件:
<?php
if( !isset( $_SESSION ) ) session_start();
if( !isset( $_SESSION['username'] ) ) exit( header('Location: index.php') );
?>
答案 0 :(得分:1)
只需在header.php中编写if / else语句:
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<?php if(!empty($_SESSION['username']): ?>
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><b>Login</b> <span class="caret"></span></a> </div>
....
<?php else: ?>
Whatever you want to display if user is not logged in... </div>
<?php endif; ?>
答案 1 :(得分:1)
这样的事情对你有用:
首先,复制当前的登录菜单,然后将其直接粘贴到自身下方。然后,您将<?php if ( user_is_logged_in() ) { ?>
放在第一个<?php } else { ?>
之上,<?php } ?>
放在第二个之上,if ( user_is_logged_in() ) {
// TODO: edit this copy
?>
LOGINFORM
<? php
} else {
?>
LOGINFORM
<?php
}
放在第二个之下。然后编辑第一个看起来就像你想要用户登录一样。
所以这个想法是这样的:
<?php
如果您在HTML中使用它,则需要将其包含在?>
和header.php
中。
以下是....
<?php include 'buttons.php' ?>
<?php
if ( isset( $_SESSION['username'] ) ) // user is logged in
{
?>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<b><?php echo $_SESSION['username'];?> </b> <span class="caret"></span>
</a>
...
</ul>
<?php
}
else // not logged in
{
?>
<!-- Login Form -->
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<b>Login</b> <span class="caret"></span>
</a>
...
</ul>
<!-- /.Login Form -->
<?php
}
?>
..rest of file
:
library(spatstat)
# Artificial data similar to the question
set.seed(42)
X1 <- rmpoint(100, win = square(10), types = factor(LETTERS[1:5]))
X2 <- rmpoint(100, win = square(10), types = factor(LETTERS[1:5]))