简体   繁体   中英

Show Log out if user logged in.

I have set up a PHP login form within dreamweaver. When dreamweaver inserted the code it worked fine but what I want my head.php file to do is detect if user is logged in. If the user is logged in i want it to Display Logout and If they are not logged in to display login. This is what I have tried..:

if ($isValid = true) {
    include 'head/hp1.php';
    ?>
    Login
    <?php
    include 'head/hp2.php';
}
else {
        include 'head/hp1.php';
    ?>
    Logout
    <?php
    include 'head/hp2.php';
}

this is the full code.

($isValid = true) is an assignment.

You want to use a comparison operator in a condition: if ($isValid === true) .

The way you currently have it, the else block will never be executed. I would also use more declarative coding habits - what is valid? I would assume a valid session and therefore prompt a logout, which is backwards from your code. This is what I would do:

<?php
    include('head/hp1.php');
    echo ($isLoggedIn === true) ? 'Logout' : 'Login';
    include('head/hp2.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM