Hiding button if PHP != session
I have a few buttons that I don't want visible to a user if they are not logged it (if $_SESSION['uid'] ='';) What is the best way to do this?
The buttons that need to b开发者_如何学Goe hidden are:
<input type='button' id='forgothide' value='Forgot My Password' >
<input type='button' id='loginhide' value='Login' >
Within the HTML/PHP code you simply need to do...
[HTML bits...]
<?php
if(!$_SESSION['uid']) {
?>
<input type='button' id='forgothide' value='Forgot My Password' >
<input type='button' id='loginhide' value='Login' >
<?php
}
?>
[Other HTML bits...]
...and all should be well.
The short and simple if statement is:
if (empty($_SESSION['uid']))
{
//uid NOT set OR evaluates to FALSE
}
else
{
//uid is set AND evaluates to true (but not necessarily correct)
}
$buttons = "";
if(!empty($_SESSION['uid']){
$buttons = "<input type='button' id='forgothide' value='Forgot My Password' >
<input type='button' id='loginhide' value='Login' >";
}
精彩评论