如果用户已定义为$ admin,则在配置文件上显示图标

时间:2016-10-01 14:25:04

标签: php

我正在一个小论坛上工作,我希望能很容易找到一名工作人员。

目前,用户在配置文件中被定义为$ admin:

<?php
/******************************************************
------------------Required Configuration---------------
Please edit the following variables so the forum can
work correctly.
******************************************************/

//We log to the DataBase
mysql_connect('127.0.0.1', 'root', '');
mysql_select_db('forum_database');

//Forum Staff
$admin='The_Darthonian'; // For admin forum features

/******************************************************
-----------------Optional Configuration----------------
******************************************************/

//Forum Home Page
$url_home = 'index.php';

//Design Name
$design = 'default';


/******************************************************
----------------------Initialization-------------------
******************************************************/
include('init.php');
?>

如果用户被定义为管理员,我希望在个人资料中显示default/images/role_moderator.gif路径上的图标

我还有一个userid变量。例如,第一个帐户将是1,然后是第二个帐户,依此类推,这是唯一的。以下是个人资料代码:

<?php
//This page display the profile of an user
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>User Profile</title>
    </head>
    <body>
        <div class="header">
            <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>
        </div>
        <div class="content">
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
    <div class="box_left">
        <a href="<?php echo $url_home; ?>">Home</a> &gt; <a href="users.php">Users</a> &gt; Profile
    </div>
    <div class="box_right">
        <a href="list_pm.php">Your messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Logout</a>)
    </div>
    <div class="clean"></div>
</div>
<?php
}
else
{
?>
<div class="box">
    <div class="box_left">
        <a href="<?php echo $url_home; ?>">Home</a> &gt; <a href="users.php">Users</a> &gt; Profile
    </div>
    <div class="box_right">
        <a href="signup.php">Sign Up</a> - <a href="login.php">Login</a>
    </div>
    <div class="clean"></div>
</div>
<?php
}
if(isset($_GET['id']))
{
    $id = intval($_GET['id']);
    $dn = mysql_query('select username, email, avatar, signup_date from users where id="'.$id.'"');
    if(mysql_num_rows($dn)>0)
    {
        $dnn = mysql_fetch_array($dn);
?>
This is the profile of "<?php echo htmlentities($dnn['username']); ?>" :
<?php
if($_SESSION['userid']==$id)
{
?>
<br /><div class="center"><a href="edit_profile.php" class="button">Edit my profile</a></div>
<?php
}
?>
<table style="width:500px;">
    <tr>
        <td><?php
if($dnn['avatar']!='')
{
    echo '<img src="'.htmlentities($dnn['avatar'], ENT_QUOTES, 'UTF-8').'" alt="Avatar" style="max-width:100px;max-height:100px;" />';
}
else
{
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
            <title></title>
        </head>
        <body>
            <?php
            ?>
            <div>
            <img src="default/images/no_avatar.jpg" alt="no_avatar" />
            </div>
        </body>
    </html>
<?php
}
?></td>
        <td class="left"><h1><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></h1>
        This user joined the website on <?php echo date('Y/m/d',$dnn['signup_date']); ?></td>
    </tr>
</table>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']!=$dnn['username'])
{
?>
<br /><a href="new_pm.php?recip=<?php echo urlencode($dnn['username']); ?>" class="big">Message "<?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?>"</a>
<?php
}
    }
    else
    {
        echo 'We could not find this user anywhere. Prehaps their account was removed.';
    }
}
else
{
?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
            <title></title>
        </head>
        <body>
            <?php
            ?>
            <div>
            <img src="/default/images/no_avatar.jpg" alt="no_avatar" />
            </div>
        </body>
    </html>
<?php
}
?>
        </div>
        <div class="foot"><a href="about.php">About Us</a> - <a href="termsofservice.php">Terms of Service</a></div>
    </body>
</html>

如何在配置中将用户定义为$ admin时,如何将其显示在个人资料中?

0 个答案:

没有答案