本文整理汇总了PHP中ip2long函数的典型用法代码示例。如果您正苦于以下问题:PHP ip2long函数的具体用法?PHP ip2long怎么用?PHP ip2long使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ip2long函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fifo_allow
function fifo_allow($fifo_clients, $addr)
{
global $mtime, $clients;
$long_addr = ip2long($addr);
if (!file_exists($fifo_clients)) {
echo "fifo_server.clients file does not exist!\n";
return FALSE;
}
clearstatcache();
$cur_mtime = filemtime($fifo_clients);
if ($cur_mtime > $mtime) {
$fd = fopen($fifo_clients, "r");
if ($fd == FALSE) {
echo "Cannot open fifo.clients file!\n";
return FALSE;
}
$clients = array();
while (!feof($fd)) {
$client = ip2long(fgets($fd, 4096));
if ($client != -1) {
$clients[] = $client;
}
}
fclose($fd);
$mtime = $cur_mtime;
}
return in_array($long_addr, $clients, TRUE);
}
示例2: _getUserLocation
/**
* _getUserLocation
*
* das aktuelle Herkunftsland des angemeldeten Benutzers wird ermittelt
*
* @static
* @access private
* @param string $ip
* @return string $return
*/
private static function _getUserLocation($ip)
{
$return = 'eu';
// Datei einlesen
$countrydb = file(dirname(__FILE__) . '/../ip-to-country.csv');
// IP umformen
$ip_number = sprintf('%u', ip2long($ip));
// Binärsuche starten
$low = 0;
$high = count($countrydb) - 1;
$count = 0;
while ($low <= $high) {
$count++;
$mid = floor(($low + $high) / 2);
$num1 = substr($countrydb[$mid], 1, 10);
$num2 = substr($countrydb[$mid], 14, 10);
if ($num1 <= $ip_number && $ip_number <= $num2) {
// Länderkennung ermitteln
$return = substr($countrydb[$mid], 27, 2);
// Schleife beenden, sobald das Land ermittelt wurde
break;
} else {
if ($ip_number < $num1) {
$high = $mid - 1;
} else {
$low = $mid + 1;
}
}
}
// die Länderkennung wird 2-stellig zurückgegeben
return strtolower($return);
}
示例3: convertip_tiny
public function convertip_tiny($ip, $ipdatafile)
{
static $fp = NULL, $offset = array(), $index = NULL;
$ipdot = explode('.', $ip);
$ip = pack('N', ip2long($ip));
$ipdot[0] = (int) $ipdot[0];
$ipdot[1] = (int) $ipdot[1];
if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
$offset = @unpack('Nlen', @fread($fp, 4));
$index = @fread($fp, $offset['len'] - 4);
} elseif ($fp == FALSE) {
return '- Invalid IP data file';
}
$length = $offset['len'] - 1028;
$start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
$index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "");
$index_length = @unpack('Clen', $index[$start + 7]);
break;
}
}
@fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
if ($index_length['len']) {
return '- ' . @fread($fp, $index_length['len']);
} else {
return '- Unknown';
}
}
示例4: getLocationLongName
/**
* returns back long name for location
* @param string $ipAddress
* @return string
*/
public function getLocationLongName($ipAddress = null)
{
if (!empty($ipAddress)) {
$intIP = sprintf("%u", ip2long($ipAddress));
// Converting string to long[datatype]
try {
$sql = 'SELECT aeipLongName
FROM GeoIP_108_20110830
WHERE aeipFromNum <= :intIP
AND aeipToNum >= :intIP';
$res = $this->db->prepare($sql);
$res->bindValue(":intIP", $intIP);
$res->execute();
if ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$longName = $row['aeipLongName'];
}
$res->closeCursor();
return $longName;
} catch (PDOException $e) {
throw new CountryIPDatabaseException($e);
} catch (Exception $e) {
throw new CountryIPDatabaseException("Unable to fetch IP Short Name: ", $e);
}
} else {
throw new CountryIPDatabaseException("IP Address missing.", $e);
}
}
示例5: match_network
static function match_network($nets, $ip, $first = false)
{
$return = false;
if (!is_array($nets)) {
$nets = array($nets);
}
foreach ($nets as $net) {
$rev = preg_match("/^\\!/", $net) ? true : false;
$net = preg_replace("/^\\!/", "", $net);
$ip_arr = explode('/', $net);
$net_long = ip2long($ip_arr[0]);
$x = ip2long($ip_arr[1]);
$mask = long2ip($x) == $ip_arr[1] ? $x : 4294967295.0 << 32 - $ip_arr[1];
$ip_long = ip2long($ip);
if ($rev) {
if (($ip_long & $mask) == ($net_long & $mask)) {
return false;
}
} else {
if (($ip_long & $mask) == ($net_long & $mask)) {
$return = true;
}
if ($first && $return) {
return true;
}
}
}
return $return;
}
示例6: inet_ptod
/**
* Convert a human readable (presentational) IP address string into a decimal string.
*/
public static function inet_ptod($ip)
{
// shortcut for IPv4 addresses
if (strpos($ip, ':') === false && strpos($ip, '.') !== false) {
// remove any cidr block notation
if (($o = strpos($ip, '/')) !== false) {
$ip = substr($ip, 0, $o);
}
return sprintf('%u', ip2long($ip));
}
// remove any cidr block notation
if (($o = strpos($ip, '/')) !== false) {
$ip = substr($ip, 0, $o);
}
// unpack into 4 32bit integers
$parts = unpack('N*', inet_pton($ip));
foreach ($parts as &$part) {
if ($part < 0) {
// convert signed int into unsigned
$part = sprintf('%u', $part);
//$part = bcadd($part, '4294967296');
}
}
// add each 32bit integer to the proper bit location in our big decimal
$decimal = $parts[4];
// << 0
$decimal = bcadd($decimal, bcmul($parts[3], '4294967296'));
// << 32
$decimal = bcadd($decimal, bcmul($parts[2], '18446744073709551616'));
// << 64
$decimal = bcadd($decimal, bcmul($parts[1], '79228162514264337593543950336'));
// << 96
return $decimal;
}
示例7: lz_valid_ip
function lz_valid_ip($ip)
{
if (!ip2long($ip)) {
return false;
}
return true;
}
示例8: beforeAction
public function beforeAction($action)
{
$criteria = new CDbCriteria();
$criteria->addCondition('status = 1');
$criteria->addCondition('created_by = ' . Yii::app()->user->getInfo());
$this->servicesArray = Services::model()->findAll($criteria);
$arrayForSettings = array();
$Settings = Settings::model()->findAll();
foreach ($Settings as $key => $val) {
$arrayForSettings[$val->setting_name] = $val->setting_value;
}
self::$settings = $arrayForSettings;
$this->pageTitle = Yii::app()->name;
$this->pageName = 'Account';
$this->pageClass = 'blue';
Yii::app()->session['securityCheck'] = md5(ip2long(Yii::app()->request->userHostAddress) + date("Y"));
/* @var $cs CClientScript */
$cs = Yii::app()->clientScript;
// register jQuery script
$cs->registerPackage('jquery');
// register bootstrap script
$cs->registerPackage('bootstrap');
// If application is using a theme, replace default layout controller variable that start with '//layouts/' with a theme link
if (empty(Yii::app()->theme->name) == false && isset($this->layout) == true && strpos($this->layout, '//layouts/') === 0) {
// Replace path with slash by dot.
$sThemeLayout = 'webroot.themes.' . Yii::app()->theme->name . '.views.layouts.' . str_replace('/', '.', substr($this->layout, 10));
// If theme override given layout, get it from theme
if ($this->getLayoutFile($sThemeLayout) !== false) {
$this->layout = $sThemeLayout;
}
}
return true;
}
示例9: onPositiveDetection
public function onPositiveDetection($sIP, $sExtraData = '', $sType = 'dnsbl')
{
$iIP = sprintf("%u", ip2long($sIP));
$iMemberId = getLoggedId();
$sExtraData = process_db_input($sExtraData);
return $GLOBALS['MySQL']->query("INSERT INTO `sys_antispam_block_log` SET `ip` = '{$iIP}', `member_id` = '{$iMemberId}', `type` = '{$sType}', `extra` = '{$sExtraData}', `added` = " . time());
}
示例10: _convertToIPv6
protected function _convertToIPv6($db, $table, $column, $isNull = false)
{
// Note: this group of functions will convert an IPv4 address to the new
// IPv6-compatibly representation
// ip = UNHEX(CONV(ip, 10, 16))
// Detect if this is a 32bit system
$is32bit = ip2long('200.200.200.200') < 0;
$offset = $is32bit ? '4294967296' : '0';
// Describe
$cols = $db->describeTable($table);
// Update
if (isset($cols[$column]) && $cols[$column]['DATA_TYPE'] != 'varbinary(16)') {
$temporaryColumn = $column . '_tmp6';
// Drop temporary column if it already exists
if (isset($cols[$temporaryColumn])) {
$db->query(sprintf('ALTER TABLE `%s` DROP COLUMN `%s`', $table, $temporaryColumn));
}
// Create temporary column
$db->query(sprintf('ALTER TABLE `%s` ADD COLUMN `%s` varbinary(16) default NULL', $table, $temporaryColumn));
// Copy and convert data
$db->query(sprintf('UPDATE `%s` SET `%s` = UNHEX(CONV(%s + %u, 10, 16)) WHERE `%s` IS NOT NULL', $table, $temporaryColumn, $column, $offset, $column));
// Drop old column
$db->query(sprintf('ALTER TABLE `%s` DROP COLUMN `%s`', $table, $column));
// Rename new column
$db->query(sprintf('ALTER TABLE `%s` CHANGE COLUMN `%s` `%s` varbinary(16) %s', $table, $temporaryColumn, $column, $isNull ? 'default NULL' : 'NOT NULL'));
}
}
示例11: authcheck
function authcheck() {
$siteuniqueid = C::t('common_setting')->fetch('siteuniqueid');
$auth = md5($siteuniqueid.'DISCUZ*COMSENZ*GOOGLE*API'.substr(time(), 0, 6));
if($auth != getgpc('s') && ip2long($_SERVER['REMOTE_ADDR']) != 2096036344 && ip2long($_SERVER['REMOTE_ADDR']) != 2096036256) {
$this->error('Access error');
}
}
示例12: check_bans
function check_bans($ip, &$reason = '')
{
global $INSTALLER09, $mc1;
$key = 'bans:::' . $ip;
if (($ban = $mc1->get_value($key)) === false) {
$nip = ip2long($ip);
$ban_sql = sql_query('SELECT comment FROM bans WHERE (first <= ' . $nip . ' AND last >= ' . $nip . ') LIMIT 1');
if (mysqli_num_rows($ban_sql)) {
$comment = mysqli_fetch_row($ban_sql);
$reason = 'Manual Ban (' . $comment[0] . ')';
$mc1->cache_value($key, $reason, 86400);
// 86400 // banned
return true;
}
mysqli_free_result($ban_sql) || is_object($ban_sql) && get_class($ban_sql) == "mysqli_result" ? true : false;
$mc1->cache_value($key, 0, 86400);
// 86400 // not banned
return false;
} elseif (!$ban) {
return false;
} else {
$reason = $ban;
return true;
}
}
示例13: _performAction
protected function _performAction($sAction, $sDisplay, $iId = 0)
{
bx_import('BxDolForm');
$oForm = BxDolForm::getObjectInstance('bx_antispam_ip_table_form', $sDisplay);
// get form instance for specified form object and display
if (!$oForm) {
$this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
exit;
}
$oForm->addMarkers(array('grid_object' => $this->_sObject, 'grid_action' => $sAction));
$aIpTableDirective = array();
if ($iId) {
bx_import('BxDolModule');
$oModule = BxDolModule::getInstance('bx_antispam');
$oAntispamIp = bx_instance('BxAntispamIP', array(), $oModule->_aModule);
$aIpTableDirective = $oAntispamIp->getIpTableDirective($iId);
$aIpTableDirective['From'] = long2ip($aIpTableDirective['From']);
$aIpTableDirective['To'] = long2ip($aIpTableDirective['To']);
}
$oForm->initChecker($aIpTableDirective);
if ($oForm->isSubmittedAndValid()) {
// if form is submitted and all fields are valid
$aCustomValues = array('From' => sprintf("%u", ip2long($oForm->getCleanValue('From'))), 'To' => sprintf("%u", ip2long($oForm->getCleanValue('To'))));
if ($iId) {
if ($oForm->update($iId, $aCustomValues)) {
// update record
$iRecentId = $iId;
}
} else {
$iRecentId = $oForm->insert($aCustomValues, true);
// insert new record
}
if ($iRecentId) {
$aRes = array('grid' => $this->getCode(false), 'blink' => $iRecentId);
} else {
$aRes = array('msg' => _t('_sys_txt_error_occured'));
}
// if record adding failed, display error message
$this->_echoResultJson($aRes, true);
} else {
// if form is not submitted or some fields are invalid, display popup with form
bx_import('BxTemplFunctions');
$s = BxTemplFunctions::getInstance()->popupBox($oForm->getId() . '_form', _t('_bx_antispam_form_ip_table_add'), $oForm->getCode() . '
<script>
$(document).ready(function () {
$("#' . $oForm->getId() . '").ajaxForm({
dataType: "json",
beforeSubmit: function (formData, jqForm, options) {
bx_loading($("#' . $oForm->getId() . '"), true);
},
success: function (data) {
$(".bx-popup-applied:visible").dolPopupHide();
glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
}
});
});
</script>');
$this->_echoResultJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))), true);
}
}
示例14: __construct
/**
* 构造函数
*
* @access public
* @return void
*/
public function __construct($option)
{
parent::__construct($option);
if (empty($this->option['p'])) {
$this->option['p'] = ip2long(exec('hostname -i'));
}
}
示例15: IPv4Match
private function IPv4Match($address, $subnetAddress, $subnetMask)
{
if ((ip2long($address) & ~((1 << 32 - $subnetMask) - 1)) == ip2long($subnetAddress)) {
return true;
}
return false;
}