Paulius Kvasnickis
Paulius Kvasnickis

Reputation: 1

How to Hide/Show Div when session is started with PHP

I have a problem with PHP. When user is logged in, or session is started, I want to hide div class, which is button "Login".

How can I make this with PHP?

Upvotes: 0

Views: 192

Answers (1)

MatsLindh
MatsLindh

Reputation: 52802

Instead of trying to hide it, never output the div if the session has login information.

I.e. in your template / code that's outputting the HTML, check if the session is present (you'll have to swap user with whatever key you're storing the valid login under):

<?php
if (empty($_SESSION['user'])):
?>
    <div class="login"> ... </div>
<?php
endif;
?>

.. and if you need it in a function:

<?php
function show_login_if_unknown() {
    if (empty($_SESSION['user'])) {
        echo '<div class="login"> ... </div>'; // or use ?> ... <?php
    }
}

Upvotes: 1

Related Questions