user547794
user547794

Reputation: 14521

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 be hidden are:

    <input type='button' id='forgothide' value='Forgot My Password' >
<input type='button' id='loginhide' value='Login' >

Upvotes: 1

Views: 2872

Answers (3)

zzzzBov
zzzzBov

Reputation: 179156

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)
}

Upvotes: 2

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

$buttons = "";

if(!empty($_SESSION['uid']){
$buttons = "<input type='button' id='forgothide' value='Forgot My Password' >
<input type='button' id='loginhide' value='Login' >";
}

Upvotes: 0

John Parker
John Parker

Reputation: 54445

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.

Upvotes: 5

Related Questions