【问题标题】:external php script for check ban on mybb users用于检查禁止 mybb 用户的外部 php 脚本
【发布时间】:2013-05-19 14:25:28
【问题描述】:

伙计们,我需要一个函数来添加我的外部 php 脚本以检查 mybb 用户的禁令

如果用户被禁止,我希望这个函数检查数据库,返回这个回显: 第 1 行:您被禁止进入此版块 第 2 行:禁止原因:$banreason 第 3 行:禁止时间:$bantime

各位看,我不是程序员,所以我知道这段代码有很多问题我只是想告诉你我需要什么:

<?php
class ban
{
Function check_ban($uid)
{
  $sql = "Select * From mybb_banned ORDER BY dateline DESC LIMIT 30";
  $result=mysql_query($sql);

  if($mybb->user['uid'] = $result2 ['uid'])
    {
     return array( 'banreason' => $result['baneason'] ,
                   'bantime'   => $result[ 'bantime' ],
                 );
    }
 }
}

$result2 = $ban->check_ban( $uid );

if( $result == false )
{
    echo "you are banned\n" ;
    echo $result[ 'banreason' ]."\n" ;
    echo $result[ 'bantime' ] ;
}
?>

谢谢

【问题讨论】:

    标签: php mybb


    【解决方案1】:

    您将结果 id 分配给用户 id,而不是比较它们。另外我认为您混淆了$result$result2

    另一个问题是你需要遍历所有被禁止的成员并检查每个

    更简洁的方法是执行以下操作:

    class ban
    {    
        static function check_ban($username)
        {
          // only fetch results for that uid
          $sql = "Select * From mybb_banned INNER JOIN mybb_users ON mybb_banned.uid = mybb_users.uid ORDER BY dateline DESC LIMIT 30 WHERE mybb_users.username=$username";
          $result=mysql_query($sql);
    
          if(mysql_num_rows($result)) // check if any entries where returned from the database
            {
             return array( 'banreason' => $result['mybb_banned.banreason'] ,
                           'bantime'   => $result[ 'mybb_banned.bantime' ],
                         );
            }
          else return false;
        }
    }
    
    if( ban::check_ban( $username ) )
    {
        echo "you are banned\n" ;
        echo $result[ 'banreason' ]."\n" ;
        echo $result[ 'bantime' ] ;
    }
    

    在这里,我将 check_ban 方法设为静态,因此您无需实例化 ban 实例即可使用它。

    编辑:我已经编辑了上面的代码,以便它通过加入 mybb_users 和 mybb_banned 表来基于用户名进行搜索(将其视为临时将两个表组合成一个使用 uid 匹配行的表)

    【讨论】:

    • 谢谢,但是如何在 mybb 中检查 $uid,因为用户只使用用户名和密码,但我需要用 $username 清除 $uid。
    • 致命错误:类名必须是第 65 行 ... 中的有效对象或字符串。第 65 行是:if( $ban::check_ban( $username ) )
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2019-08-28
    • 2012-04-30
    • 2011-03-17
    • 2021-09-09
    相关资源
    最近更新 更多