I am trying to create a little admin-only navigation panel for my site that should only be visible when an admin has logged in. I have all the session logic working fine I just am not sure on one thing.
Is it more standard practice to have the navigation panel HTML code always in the source, but just change the display property using PHP based on whether or not the user is logged in as admin? So something like
<head>
<?php
if($_SESSION['loggedin']) {
echo "<style>#adminPanel { display:block; }</style>";
}
?>
</head>
while having the original CSS display:none;?
or
having PHP echo the full adminPanel HTML if the user is logged in?
Like:
<?php
if($_SESSION['loggedin'])
{
?>
//HTML for adminPanel goes here
<?php
}
?>
I basically want to know what method is standard, or if they are equally acceptable?
Thanks
I am not sure if this question is considered subjective, so sorry if it is.
Users can edit CSS on-the-fly and expose your admin panel in the first method. Therefore, the second is preferable since you won’t be outputting anything you don’t want the user to see.