在写上下文中不能使用函数返回值

时间:2014-03-08 23:21:01

标签: php login mybb

所以我正试图与MyBB进行一次中途登录集成,成功后会在某个区域显示他们的头像。

这是我用来检查有效性并在HTML img标签中显示头像的if语句。

if (isset($mybb) && isset($mybb->user['avatar'])) {
    if (substr($mybb->user['avatar'], 0, 4) = 'http') {
        echo $mybb->user['avatar'];
    } else {
        echo('../../Forums/' . $mybb->user['avatar']);
    }
}

我仍然不明白这有什么问题 - 我在PHP错误日志中被抛出:

  

[08-Mar-2014 23:08:46 UTC] PHP致命错误:无法在第26行的/home/ponypwna/public_html/Login.php中的写入上下文中使用函数返回值

请注意,此PHP语句位于所有一行上 - 如下面的完整代码所示:

  <!DOCTYPE html>
  <html>
  <head>
  <link href="./include/css/bootstrap.css" rel="stylesheet">
  </head>
  <body>

    <?php
     include("./include/nbar.php");
    ?>

    <!-- Mane Area -->
    <div class="container">
      <div class="row">
        <div class="col-md-4 col-md-offset-2">
        <br /><br /><br /><p />
          <!--Login and Register Here BIG so in seperate file-->
        <p>
          <!--Login SUCCESS -->
          <?php if($mybb->user['uid']){ ?>
            <div class="panel panel-success">
              <div class="panel-heading">
                <h3 class="panel-title"><span class="glyphicon glyphicon-thumbs-up"></span> Login Success</h3>
              </div>
              <div class="panel-body">
                <div class="col-xs-6 col-md-3"><a href="../../Forums/member.php?action=profile&uid=<?php echo $mybb->user['uid'] ?>" class="thumbnail"><img src="<?php if (isset($mybb) && isset($mybb->user['avatar'])) { if (substr($mybb->user['avatar'], 0, 4) = 'http') { echo $mybb->user['avatar']; } else { echo('../../Forums/' . $mybb->user['avatar']); } } ?>" /></a></div>
                You have successfully logged in as <?php echo $mybb->user['username']; ?>.
              </div>
            </div>
            <?php } else { ?>
        <!--Login DEFAULT -->
        <?php if(isset($_GET['su'])){ ?>
          <div style="display:none;">
        <?php } else { ?>    
        <div class="panel panel-primary">
        <?php } ?>
          <div class="panel-heading">
            <h3 class="panel-title"><span class="glyphicon glyphicon-th-large"></span> Login</h3>
          </div>
          <div class="panel-body">
            <form action="../../Forums/member.php" class="ajaxform" method="post">
              <div class="form-group">
                 <label for="exampleInputEmail1">Username:</label>
                <input type="text" class="form-control" id="exampleInputEmail1" name="username" placeholder="Ex: LordNature" required>
              </div>
               <div class="form-group">
                <label for="exampleInputPassword1">Password:</label>
                <input type="password" class="form-control" id="exampleInputPassword1" name="password" placeholder="*******" required>
              </div>
              <input type='hidden' name='action' value='do_login'>
              <input type='hidden' name='url' value='../../Login' />
              <input type="submit" class="btn btn-primary" value="Login" name="submit" />
            </form>      
          </div>
        </div>
                <?php } ?></p>
        </div>
        <div class="col-md-4">
          <br /><br /><br /><p />
          <b>
          <div class="list-group">
            <a class="list-group-item active">
              <font size="4">TTT Rules</font>
            </a>
            <a class="list-group-item"><font size="2">1.  Please obey the Staff.</a></font>
            <a class="list-group-item"><font size="2">2.  Do not RDM.</a></font>
            <a class="list-group-item"><font size="2">3.  Do not camp in T rooms for over 2 minutes.</a></font>
            <a class="list-group-item"><font size="2">4.  Do not harass or bully others.</a></font>
            <a class="list-group-item"><font size="2">5.  Do not be annoying.</a></font>
            <a class="list-group-item"><font size="2">6.  Do not propkill.</a></font>
            <a class="list-group-item"><font size="2">7.  Do not metagame.</a></font>
            <a class="list-group-item"><font size="2">8.  Do not hack or exploit.</a></font>
            <a class="list-group-item"><font size="2">9.  Do not micspam.</a></font>
            <a class="list-group-item"><font size="2">10.  Do not kill AFK players.</a></font>
          </div></b></p>
       </div>
      </div>
      <hr>

      <?php include("./include/footer.php"); ?>

      </hr>
    </div> <!-- /container -->
  </body>
</html>

我是PHP的新手,所以请忽略我的愚蠢。

2 个答案:

答案 0 :(得分:1)

if (substr($mybb->user['avatar'], 0, 4) = 'http')

...尝试分配substr。

的结果
if (substr($mybb->user['avatar'], 0, 4) == 'http')

...可能就是您的意思(注意==(或===)而不是=

答案 1 :(得分:-2)

除变量之外,您不能使用isset,即使在 big red box in the official documentation 中也是如此!这意味着您可能需要将您的条件重构为

之类的内容
if (isset($mybb) && property_exists($mybb, "user") && array_key_exists("avatar", $mybb->user)) {