Hide and show div depending on session

I have an admin link with a div id "admin". Sessions are started when the user is logged in to show if he is a regular user or an administrator. Regular users cannot access files for admin, but can still see the admin link.

Is there a way to prevent regular users from seeing the link using only php

or html

, without jquery

or jscript or any of them.

0


source to share


2 answers


Using alternating PHP and HTML with standard PHP syntax:

<?php
if ($user_is_an_admin) {
?>
<div id='admin'>
  Only admins can see this...
</div>
<?php
}
?>

      

Alternative template syntax:



<?php if ($user_is_an_admin): ?>
<div id='admin'>
      Only admins can see this...
</div>
<?php endif; ?>

      

Not interspersed, PHP only:

if ($user_is_an_admin) {
  echo "<div id='admin'>
      Only admins can see this...
     </div>
  ";
}

      

+4


source


You will need to use conditionals inside your views:



<?php if($_SESSION['adminid'] == 1234): ?>
    <!-- Admin div goes here -->
<?php else: ?>
    <!-- Admin link goes here -->
<?php endif; ?>

      

+2


source







All Articles