用户登录 php 后更改导航栏



我希望导航栏中的"登录/注册"按钮在用户登录后更改为"我的帐户"。

我用于此的导航.php文件目前如下所示:

<?php 
    session_start();
    include("check.php");   
?>

<?php 
if ($_SESSION['username']){ ?>
    <div id="nav">
        <ul >
            <li class="navbar-left"><a href="artikelen.html">Men</a></li>
            <li class="navbar-left"><a href="artikelen.html">Women</a></li>
            <li class="navbar-left"><a href="artikelen.html">Kids</a></li>
            <li class="navbar-right"><a href="view_cart.php">Cart (0)</a></li>
            <li class="navbar-right"><a href="inlog.php">My Account</a></li>
        </ul>
    </div>
<?php } else { ?>
    <div id="nav">
        <ul >
            <li class="navbar-left"><a href="artikelen.html">Men</a></li>
            <li class="navbar-left"><a href="artikelen.html">Women</a></li>
            <li class="navbar-left"><a href="artikelen.html">Kids</a></li>
            <li class="navbar-right"><a href="view_cart.php">Cart (0)</a></li>
            <li class="navbar-right"><a href="inlog.php">Login / Sign Up</a></li>
        </ul>
    </div> 
<?php }
?>

检查.php文件如下所示:

<?php
include('connection.php');
session_start();
$user_check=$_SESSION['username'];
$ses_sql = mysqli_query($db,"SELECT username FROM users WHERE username='$user_check' ");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_user=$row['username'];
if(!isset($user_check))
{
header("Location: index.php");
}
?>

如果我转到带有此导航栏的网页,则会出现以下错误:

此网页有一个重定向循环ERR_TOO_MANY_REDIRECTS

有人可以帮我吗?

更新你的支票.php像这样。

$user_check = (isset($_SESSION['username']) && trim($_SESSION['username'])!='')?trim($_SESSION['username']):false;
if(!$user_check) header("Location: index.php");
else{
    $ses_sql = mysqli_query($db,"SELECT username FROM users WHERE username='$user_check' ");
    $row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC); 
    $$_SESSION['username']=$row['username'];
}

删除选中的位置标头.php。您可以在显示登录表单后设置位置标题

试试这个

导航.php

<?php 
    include("check.php");   
?>

    <?php 
    if ($loginst == 1){ ?>
        <div id="nav">
            <ul >
                <li class="navbar-left"><a href="artikelen.html">Men</a></li>
                <li class="navbar-left"><a href="artikelen.html">Women</a></li>
                <li class="navbar-left"><a href="artikelen.html">Kids</a></li>
                <li class="navbar-right"><a href="view_cart.php">Cart (0)</a></li>
                <li class="navbar-right"><a href="inlog.php">My Account</a></li>
            </ul>
        </div>
    <?php } else { ?>
        <div id="nav">
            <ul >
                <li class="navbar-left"><a href="artikelen.html">Men</a></li>
                <li class="navbar-left"><a href="artikelen.html">Women</a></li>
                <li class="navbar-left"><a href="artikelen.html">Kids</a></li>
                <li class="navbar-right"><a href="view_cart.php">Cart (0)</a></li>
                <li class="navbar-right"><a href="inlog.php">Login / Sign Up</a></li>
            </ul>
        </div> 
    <?php } ?>

检查.php

<?php
include('connection.php');
session_start();
$loginst = 0;
if ($_SESSION['username']){ 
$user_check = $_SESSION['username'];
$ses_sql = mysqli_query($db,"SELECT username FROM users WHERE username='$user_check' ");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_user=$row['username'];
if(!empty($login_user)) 
{
   $loginst = 1;
}
}
?>

相关内容

  • 没有找到相关文章

最新更新