简体   繁体   English

PHP条件显示两个结果

[英]PHP conditionals showing both results

I have the following on a php page which does not want to work correctly. 我在php页面上有以下内容,这些页面无法正常工作。 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. <?php php未被解析。 You can confirm by viewing source on the web page. 您可以通过查看网页上的源进行确认。

Change all <? 全部更改<? to <?php , <?php

or modify your php.ini file, change short_open_tag = Off to short_open_tag = On 或修改您的php.ini文件,将short_open_tag = Off更改为short_open_tag = On

but short open tags are not recommended, you can see Are PHP short tags acceptable to use? 但不建议使用短开放标签,您可以看到可以使用PHP短标签吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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