要进行我的网站的登录/注销,我使用一个简单的按钮,该按钮会导致模式表单导致登录的日志操作。
对于注销,我发现的最好方法是使用一个虚拟表单,它只包含导致日志操作的注销按钮。
PHP代码:
<!-- Login -->
<?php
if(!isset($_SESSION['user'])) {
echo '
<button class="btn btn-outline-info my-2 my-sm-0" type="button" data-toggle="modal" data-target="#ModalExample" style="margin-left: 10px">Login</button>
';
}
else {
echo '
<form action="actions/log.php" method="post">
<input type="submit" value="Log out" class="btn btn-outline-danger my-2 my-sm-0" style="margin-left: 10px">
</form>
';
}
?>
&#13;
Navbar:
<nav class="navbar fixed-top navbar-toggleable-md navbar-light bg-faded" data-spy="affix" data-offset-top="90">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Beauty Website</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav mr-auto mt-2 mt-md-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#othersec">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#versatility">Offers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#lightbox">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#opportunities">Shop</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Appointment</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact us</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
&#13;
你知道我怎么能做得更好吗?
答案 0 :(得分:0)
感谢您的帮助,我忘了我的导航栏中有一堂课。
这是有效的PHP:
<!-- Login -->
<?php
if(!isset($_SESSION['user'])) {
echo '
<button class="btn btn-outline-info my-2 my-sm-0" type="button" data-toggle="modal" data-target="#ModalExample" style="margin-left: 10px">Login</button>
';
}
else {
echo '
<form class="form-inline my-2 my-lg-0" action="actions/log.php" method="post">
<input type="submit" value="Log out" class="btn btn-outline-danger my-2 my-sm-0" style="margin-left: 10px">
</form>
';
}
?>