if (substr($mybb->user['avatar'], 0, 4) = 'http')
...tries to assign to the result of substr.
if (substr($mybb->user['avatar'], 0, 4) == 'http')
...is probably what you mean to do (note ==
(or ===
) instead of =
)
Frage
So I'm trying to make a halfway decent login integration with MyBB, which upon success will display their avatar image in a certain area.
This is the if statement I'm using to both check the validity and display the avatar in an HTML img tag.
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']);
}
}
I still don't understand what's wrong with this- I'm being thrown this up in my PHP error log:
[08-Mar-2014 23:08:46 UTC] PHP Fatal error: Can't use function return value in write context in /home/ponypwna/public_html/Login.php on line 26
Note that this PHP statement is on all one line- as displayed in the full code below:
<!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>
I'm a novice to PHP, so please ignore my stupidity.
Lösung
if (substr($mybb->user['avatar'], 0, 4) = 'http')
...tries to assign to the result of substr.
if (substr($mybb->user['avatar'], 0, 4) == 'http')
...is probably what you mean to do (note ==
(or ===
) instead of =
)
Andere Tipps
You can't use isset
on anything else than variables, that's even in a big red box in the official documentation! This means you probably need to refactor your condition to something like
if (isset($mybb) && property_exists($mybb, "user") && array_key_exists("avatar", $mybb->user)) {