-2

因此,我正在尝试与 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的新手,所以请忽略我的愚蠢。

4

2 回答 2

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

...尝试分配给 substr 的结果。

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

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

于 2014-03-08T23:22:31.947 回答
-2

除了变量之外,您不能使用isset其他任何东西,甚至在官方文档中的一个大红色框中!这意味着您可能需要将您的条件重构为类似

if (isset($mybb) && property_exists($mybb, "user") && array_key_exists("avatar", $mybb->user)) {
于 2014-03-08T23:25:18.517 回答