简体   繁体   中英

PHP conditionals showing both results

I have the following on a php page which does not want to work correctly. I am not sure if i'm not doing the conditional correctly or not? It appears to show both sets of content irrespective if the 1st condition is true or not, any ideas?

 <? if(!isset($_SESSION['exhibitor_logged_in']) || $_SESSION['exhibitor_logged_in'] != true): ?>
    <p>Please log in with the password.</p>
    <form name="exhibitor_login" method="POST" action="">
        <div>
            <label for="password">Password:</label>
            <input type="password" name="password" />
        </div>
        <div>
            <label for="submit">&nbsp;</label>
            <input type="submit" name="submit" value="LOG IN" />
        </div>
    </form>
    <? else: ?>
        <p>Logged in</p>
    <? endif; ?>

change all of you <? to <?php php isn't being parsed. You can confirm by viewing source on the web page.

Change all <? to <?php ,

or modify your php.ini file, change short_open_tag = Off to short_open_tag = On

but short open tags are not recommended, you can see Are PHP short tags acceptable to use?

Using || will make and or comparation between the two statment, i think in your case you should use && because it should match both statment

if(!isset($_SESSION['exhibitor_logged_in']) && $_SESSION['exhibitor_logged_in'] != true): 

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