doubao6936 2018-08-03 21:36
浏览 64
已采纳

如果用户在同一页面中登录两次,则更改HTML内容[重复]

This question already has an answer here:

I am building my login system for my website, everything is working as intended however I wanted to further design a feature where if the user is logged in, echo their name with a 'Manage' bit of text before it, so ideally they would login, this new button would appear that says Manage | 'Their username'. I have managed to implement a changing 'logout/login' button so when they are logged in, 'logout' will appear and vice versa in the code below.

login change

                <?php if(isset($_SESSION['user_id']) || 
isset($_SESSION['logged in'])){ ?>
            <li> <a href="logout.php"> Logout |  <?php echo 
$_SESSION['user_id'] ?> </a></li>
            <?php }else{ ?>
            <li> <a href="loginpage.php" >login</a></li>
                <?php } ?>

This is at the top of my navbar, I have tried to apply the same principle however the page just becomes unresponsive. After adding and removing code when I only implement this section

<li> <a href="clubpage.php"> Manage |  <?php echo $_SESSION['user_id'] ?> 
</a></li>

It displays as intended, however then when attempting to create an if statement (so when no one is logged in nothing is displayed) That's when the page dies for example

<?php if(isset($_SESSION['user_id']) || isset($_SESSION['logged in'])){ ?> //   etc

Now I imagine It's an issue with the if statement, which I am calling further down obviously to change the login. Any help where I'm going wrong would be helpful, thanks in advance Error log

[03-Aug-2018 22:43:44 UTC] PHP Parse error:  syntax error, unexpected end of 
file in C:\Users\b\Desktop\code\clubpage.php on line 39

 <body>
<div class ="container">
    <header> <a href=""></a>
        <h4 class="logo"> Game Finder </h4>
    </a>
    <nav>
        <ul>
    <?php if(isset($_SESSION['user_id']) || isset($_SESSION['logged in'])){ ?>
    <li> <a href="clubpage.php"> Manage |  <?php echo $_SESSION['user_id'] ?> </a></li>
            <li> <a href="/index.php">Home</a></li>
            <li> <a href="#about"> About</a></li>
            <li> <a href="/finder.php"> Finder </a></li>
            <?php if(isset($_SESSION['user_id']) || isset($_SESSION['logged in'])){ ?>
            <li> <a href="logout.php"> Logout |  <?php echo $_SESSION['user_id'] ?> </a></li>
            <?php }else{ ?>
            <li> <a href="loginpage.php" >login</a></li>
                <?php } ?>
        </ul>
    </nav>
</header>
</div>
  • 写回答

1条回答 默认 最新

  • duanmei1850 2018-08-03 22:16
    关注

    I have found and fixed the issue! was a combination of two things, Simple really I had a syntax error where I wasn't closing the else part of the if statement here below index.php

          <?php }else{ ?>
        <li> <a href="/index.php"> ff </a></li>
        <?php } ?>
    

    Additionally this didn't fix it straight away, I read this Answer Here Which helped me change a setting in my php.ini file which fixed the issue! thanks anyway guys!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)