Mihai Procudin Mihai Procudin - 9 days ago 6
PHP Question

$_SESSION[] manipulations

I am willing to implement in my project a menubar with some restrictions for a couple of users. I faced some difficulties when setting it up.

<?session_start();
$username=$_SESSION[username];
if($username == "usern1"){?>

<ul class="nav">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>

<? }elseif($username =="usern2"){?>
show just a half of this .nav


<? }?>


PHP is selection what is first in this IF statement if I will change the order it will put the half menu .nav first.

Answer

Try following code

   <?php
     session_start();
     $username=$_SESSION['username'];
    ?>
    <ul class="nav">
    <?php
        if($username == "usern1"){
    ?>
        <li class="nav-item">
            <a class="nav-link active" href="#">Active</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" href="#">Disabled</a>
          </li>
       <?php
        } elseif ($username =="usern2") {
       ?>
         <!-- Add your li html menu here -->
       <?php
        }
       ?>
    </ul>