本文整理匯總了PHP中MatchaModel::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP MatchaModel::save方法的具體用法?PHP MatchaModel::save怎麽用?PHP MatchaModel::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MatchaModel
的用法示例。
在下文中一共展示了MatchaModel::save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isBlocked
/**
* @return bool
*/
public function isBlocked()
{
include_once ROOT . '/dataProvider/GeoIpLocation.php';
$ip = $_SERVER['REMOTE_ADDR'];
if ($ip == '::1' || $ip == '127.0.0.1') {
return false;
}
$geo_data = GeoIpLocation::getGeoLocation($ip);
if ($geo_data === false) {
$sql = 'SELECT * FROM `ip_access_rules` WHERE active = 1 AND ip = :ip1 OR ip = :ip2 ORDER BY weight DESC LIMIT 1';
$where = [];
$where[':ip1'] = '*';
$where[':ip2'] = $ip;
} else {
$sql = 'SELECT * FROM `ip_access_rules` WHERE active = 1 AND ip = :ip1 OR ip = :ip2 OR country_code = :country_code ORDER BY weight DESC LIMIT 1';
$where = [];
$where[':ip1'] = '*';
$where[':ip2'] = $ip;
$where[':country_code'] = $geo_data['country_code'];
}
$conn = Matcha::getConn();
$sth = $conn->prepare($sql);
$sth->execute($where);
$result = $sth->fetch(PDO::FETCH_ASSOC);
if ($result !== false) {
$blocked = $result['rule'] == 'BLK';
} else {
// if no rule found blocked the IP if not inside local network
$blocked = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false;
}
if ($blocked) {
$record = new stdClass();
$record->ip = $ip;
$record->country_code = $geo_data !== false ? $geo_data['country_code'] : '';
$record->event = 'Blocked';
$record->create_date = date('Y-m-d H:i:s');
$this->l->save($record);
}
return $blocked;
}