2010-12-26 10 views
1

Ich habe ein paar Knöpfe, die ich nicht sichtbar für einen Benutzer sehen will, wenn sie nicht geloggt sind (wenn $ _SESSION ['uid'] = '';) Was ist der beste Weg um dies zu tun?Verbergen Knopf wenn PHP! = Sitzung

Die Tasten, die versteckt werden müssen, sind:

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

Antwort

2

Die kurze und einfache if-Anweisung ist:

if (empty($_SESSION['uid'])) 
{ 
    //uid NOT set OR evaluates to FALSE 
} 
else 
{ 
    //uid is set AND evaluates to true (but not necessarily correct) 
} 
+0

Danke, das hat super funktioniert! – user547794

5

Innerhalb des HTML/PHP Code, den Sie einfach tun müssen ...

[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...] 

... und das alles gut sein sollte.

+0

Nicht Überprüfung 'isset' oder' empty' Fehler wird ausgelöst, wenn der Schlüssel nicht in der Sitzung gesetzt. – zzzzBov

0
$buttons = ""; 

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