dousong8187 2017-04-29 20:11
浏览 64
已采纳

当用户登录同一页面时,如何使用其他css设计更改登录<li>

I made a Navigation Bar which contain a Login , so I want to change it with a div (contain image and user's name), when the user log in !

NavBar :

 <div class="collapse navbar-collapse" id="axit-nav">
            <ul class="nav navbar-nav navbar-right">
                <li><a> <button id="myButton">Create event</button></a></li>
            </ul>
            <ul class="nav navbar-nav navbar-left">
                <li><a class="dsctv hidden-xs hidden-sm">events</a></li>
                <li><a class="dsctv hidden-xs hidden-sm">Login</a></li>
                <li><img alt="Logo brand Wevento" class="navbar-brand hidden-xs hidden-sm" src="theme/img/logos/Logo%20White%20Blue.png" </li>
            </ul>
        </div>

PHPcode :

<?php 
session_start();
if (isset($_SESSION['Mail'])) {
     header('Location: admin/index.php');
}
include 'admin/init.php';    
// Check for ADMINS
if($_SERVER['REQUEST_METHOD'] == 'POST'){

    $mail= $_POST['mail'];
    $password= $_POST['password'];
    $hashedPass= sha1($password);

    // check if the user exist in DB

    $stmt = $conn->prepare("SELECT Mail, Password FROM admin WHERE Mail= ?  AND Password = ? ");
    $stmt->execute(array($mail, $hashedPass));
    $count = $stmt->rowCount();

    if($count > 0) {
        $_SESSION['Mail'] = $mail;

    } 
}
 ?>
  • 写回答

2条回答 默认 最新

  • dsdeeaquu38538545 2017-04-29 20:49
    关注

    You need to write a check to confirm if the session exists. If yes, show the user name, if not, show the login link. Something like this:

    <div class="collapse navbar-collapse" id="axit-nav">
        <ul class="nav navbar-nav navbar-right">
            <li><a> <button id="myButton">Create event</button></a></li>
        </ul>
        <ul class="nav navbar-nav navbar-left">
            <li><a class="dsctv hidden-xs hidden-sm">events</a></li>
            <?php if (!isset($_SESSION)) { ?>
            <li><a class="dsctv hidden-xs hidden-sm">Login</a></li>
            <?php } else { ?>
            <li><a class="dsctv hidden-xs hidden-sm"><?php echo $_SESSION['user_name'];?></a></li>
            <?php } ?>
            <li><img alt="Logo brand Wevento" class="navbar-brand hidden-xs hidden-sm" src="theme/img/logos/Logo%20White%20Blue.png" </li>
        </ul>
    </div>
    

    Of course echo out the user name based on how you stored it in the session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献