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 to share