所以我试图使一半体面的登录集成与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-03-2014 23:08:46 UTC] PHP致命错误:无法在写上下文中使用函数返回值在/home/ponypwna/public_html/Login.php第26行
注意,这个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新手,所以请忽略我的愚蠢。
if (substr($mybb->user['avatar'], 0, 4) = 'http')
…尝试赋值给substr的结果。
if (substr($mybb->user['avatar'], 0, 4) == 'http')
…可能是你想做的(注意==
(或===
)而不是=
)
你不能在变量之外的任何东西上使用isset
,即使在官方文档中的大红色框中也是如此!这意味着您可能需要将条件重构为
if (isset($mybb) && property_exists($mybb, "user") && array_key_exists("avatar", $mybb->user)) {