Content Management System Ban System

Hello PHP Coders (hoping with MySQL),

So I’m developing CMS for my website and trying to create a ban system but when I ban a user their not being redirect to my banned page.

This is my class.users.php

CODE:

[php]
/-------------------------------Stuff related to bans-------------------------------------/

final public function isBanned($value)
{
	global $engine;
	 if($engine->num_rows("SELECT * FROM bans WHERE type = '" . $value . "' LIMIT 1") > 0)
    { 
            if($engine->num_rows("SELECT * FROM bans WHERE ip = '" . $value . "' LIMIT 1") > 0) 
            {
                  return true;
            }
     }
		
	return false;
}

[/php]

and this the checktheban.php

[php]

<?php if($_SESSION['user']['id']){ $getuserinfo = mysql_query("SELECT * FROM users WHERE id='".$_SESSION['user']['id']."'"); while($row = mysql_fetch_array($getuserinfo)){ $usernameban = $row['user_id']; $ipban = $row['ip']; } $getuserinfo= mysql_query("SELECT * FROM bans WHERE user_id='{$usernameban}' AND ban_expire > UNIX_TIMESTAMP() ORDER BY expire DESC LIMIT 1"); $getuserinfoip= mysql_query("SELECT * FROM bans WHERE ip='{$ipban}' AND ban_expire > UNIX_TIMESTAMP() ORDER BY expire DESC LIMIT 1"); while($row = mysql_fetch_array($getuserinfo)){ $expire = $row['ban_expire']; if($expire <= time()){ } else { header('Location: /banned'); exit; } } while($row = mysql_fetch_array($getuserinfoip)){ $expire = $row['ban_expire']; if($expire <= time()){ } else { header('Location: /ipbanned'); exit; } } } ?>

[/php]

MySQL Structure Table;


hi,

If you are using OOP checkban.php should be like that:
[php]<?php

if (isset($_SESSION[‘user’][‘id’])) {
$user = UserRepository::findById($_SESSION[‘user’][‘id’]);

if ($user && $user->isBanned()) {
    header('Location: /ipbanned');
    exit;
}

}[/php]

[php]if($engine->num_rows("SELECT * FROM bans WHERE type = '" . $value . "' LIMIT 1") > 0) { if($engine->num_rows("SELECT * FROM bans WHERE ip = '" . $value . "' LIMIT 1") > 0) [/php]
type must be one of 'account', 'ip', 'machine', 'super'. You can not pass same $value to the both queries.
Sponsor our Newsletter | Privacy Policy | Terms of Service