开发者

PHP - GET page response comes empty

I have the following code in admin.php (admin page for some kind of simple CMS):

<?php
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Pragma: no-cache");

//Some work with MySQL, setting $logged boolean and $priv variable (user's privileges)
//If $_POST['newspost'] set, processing request and setting $status

<!DOCTYPE html>
<html>
<head>
<!-- some JS and CSS includes -->
</head>

<body>
<div id="adm-content">
<h2 id="adm">Settings</h2>
<p id="news-status"><?php if (!empty($status)) echo $status; ?></p>

<?php if ($logged && $priv > 0){ ?> //user logged in and is admin
<p id="adm-status">Hello, <?php echo $_COOKIE['user'] ?></p>
<!-- some admin forms -->

<?php
}
else if ($priv == 0){ //user logged in and isn't admin
?>

<p id="adm-status">Hello, <?php echo $_COOKIE['user'] ?></p>
<p>You are not admin</p>

<?php
}
else{ ?>

<!-- login form displayed -->

?php
 } 
 ?>
</body>

</html>

All works fine except the second case (user logged in, but isn't admin). Then a blank page is displayed. As I see in FireBug, GET admin.php response comes empty. Where the problem could开发者_开发技巧 be?

Thanks for your time.


else if ($logged && $priv === 0){ //user logged in and isn't admin

You should var_dump( $priv ) and really check whether an integer is being passed, if so use === 0 and if $priv is a string then use === '0'.

I always var_dump() code which is to become the crux of a condition, you can never tell.


Problem was in handling MySQL output, in this piece of code:

$priv = mysql_result($qry, 0) or die(mysql_error());

All works fine, when I rewrite it using mysql_fetch_row

$x = mysql_fetch_row($qry);
$priv = $x[0];

Seems strange to me. Anyway, thanks for help, and sorry for not posting the actual problematic code =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜