当前位置: 首页>>代码示例>>PHP>>正文


PHP IP类代码示例

本文整理汇总了PHP中IP的典型用法代码示例。如果您正苦于以下问题:PHP IP类的具体用法?PHP IP怎么用?PHP IP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

function save()
{
    $_POST["mac"] = str_replace("-", ":", $_POST["mac"]);
    $_POST["mac"] = strtolower($_POST["mac"]);
    $ipClass = new IP();
    if (!$ipClass->IsvalidMAC($_POST["mac"])) {
        echo "MAC: {$_POST["mac"]} Invalid!\n";
        return;
    }
    if (!$ipClass->isValid($_POST["ipaddr"])) {
        echo "MAC: {$_POST["ipaddr"]} Invalid!\n";
        return;
    }
    $cmp = new computers();
    $uid = $cmp->ComputerIDFromMAC($_POST["mac"]);
    if ($uid != null) {
        $cmp = new computers($uid);
    }
    if ($uid == null) {
        $uid = "{$_POST["hostname"]}\$";
    }
    $cmp->uid = $uid;
    $cmp->ComputerIP = $_POST["ipaddr"];
    $cmp->ComputerMacAddress = $_POST["mac"];
    $cmp->ComputerRealName = $_POST["hostname"];
    if ($cmp->Add()) {
        echo $cmp->ldap_error;
    }
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:29,代码来源:ocs.add.php

示例2: CalculCDR

function CalculCDR()
{
    $ip = new IP();
    $ipfrom = $_GET["mynet_ipfrom"];
    $ipto = $_GET["mynet_ipto"];
    $SIP = $ip->ip2cidr($ipfrom, $ipto);
    echo trim($SIP);
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:8,代码来源:domains.postfix.network.php

示例3: testConstructSuccess

 public function testConstructSuccess()
 {
     $ip = new IP(TestDataGenerator::ipInt());
     $range = new Range($ip, $ip);
     $this->assertInstanceOf('Bankiru\\IPTools\\Range', $range);
     $this->assertEquals($ip->getIntValue(), $range->getStart()->getIntValue());
     $this->assertEquals($ip->getIntValue(), $range->getEnd()->getIntValue());
 }
开发者ID:bankiru,项目名称:ip-tools,代码行数:8,代码来源:RangeTest.php

示例4: dns_add

function dns_add(){
	$_POST["nameserver"]=trim($_POST["nameserver"]);
	$IPClass=new IP();
	if(!$IPClass->isValid($_POST["nameserver"])){
		echo "{$_POST["nameserver"]} invalid\n";
		return;
	}
	$nameserver[$_POST["nameserver"]]=true;
	
	$q=new mysql_squid_builder();
	$q->QUERY_SQL("INSERT INTO dns_servers (dnsserver,zOrder) VALUES ('{$_POST["nameserver"]}','1')");
	if(!$q->ok){echo $q->mysql_error;}
	
}
开发者ID:brucewu16899,项目名称:1.6.x,代码行数:14,代码来源:squid.dns.php

示例5: testPrivateIPs

 public function testPrivateIPs()
 {
     $private = array('10.0.0.1', '172.16.0.1', '192.168.0.1');
     foreach ($private as $p) {
         $this->assertFalse(IP::isPublic($p), "{$p} is not a public IP address");
     }
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:7,代码来源:IPTest.php

示例6: validate

 /**
  * @param string|MWRestrictions $value The value the field was submitted with
  * @param array $alldata The data collected from the form
  *
  * @return bool|string True on success, or String error to display, or
  *   false to fail validation without displaying an error.
  */
 public function validate($value, $alldata)
 {
     if ($this->isHidden($alldata)) {
         return true;
     }
     if (isset($this->mParams['required']) && $this->mParams['required'] !== false && $value instanceof MWRestrictions && !$value->toArray()['IPAddresses']) {
         return $this->msg('htmlform-required')->parse();
     }
     if (is_string($value)) {
         // MWRestrictions::newFromArray failed; one of the IP ranges must be invalid
         $status = Status::newGood();
         foreach (explode(PHP_EOL, $value) as $range) {
             if (!\IP::isIPAddress($range)) {
                 $status->fatal('restrictionsfield-badip', $range);
             }
         }
         if ($status->isOK()) {
             $status->fatal('unknown-error');
         }
         return $status->getMessage()->parse();
     }
     if (isset($this->mValidationCallback)) {
         return call_user_func($this->mValidationCallback, $value, $alldata, $this->mParent);
     }
     return true;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:33,代码来源:HTMLRestrictionsField.php

示例7: execute

 function execute($par)
 {
     global $wgRequest, $wgOut, $wgFundraiserLPDefaults;
     // Set the country parameter
     $country = $wgRequest->getVal('country');
     // If no country was passed do a GeoIP lookup
     if (!$country) {
         if (function_exists('geoip_country_code_by_name')) {
             $ip = wfGetIP();
             if (IP::isValid($ip)) {
                 $country = geoip_country_code_by_name($ip);
             }
         }
     }
     // If country still isn't set, set it to the default
     if (!$country) {
         $country = $wgFundraiserLPDefaults['country'];
     }
     $params = array('country' => $country);
     // Pass any other params that are set
     $excludeKeys = array('country', 'title');
     foreach ($wgRequest->getValues() as $key => $value) {
         // Skip the required variables
         if (!in_array($key, $excludeKeys)) {
             $params[$key] = $value;
         }
     }
     // Redirect to FundraiserLandingPage
     $wgOut->redirect($this->getTitleFor('FundraiserLandingPage')->getLocalUrl($params));
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:30,代码来源:FundraiserRedirector.body.php

示例8: execute

 public function execute($par)
 {
     global $wgLogRestrictions;
     $this->setHeaders();
     $this->outputHeader();
     $opts = new FormOptions();
     $opts->add('type', '');
     $opts->add('user', '');
     $opts->add('page', '');
     $opts->add('pattern', false);
     //		$opts->add( 'year', null, FormOptions::INTNULL ); don't default to zero
     $opts->add('year', '');
     $opts->add('month', null, FormOptions::INTNULL);
     $opts->add('tagfilter', '');
     $opts->add('offset', '');
     $opts->add('dir', '');
     $opts->add('offender', '');
     // Set values
     $opts->fetchValuesFromRequest($this->getRequest());
     if ($par !== null) {
         $this->parseParams($opts, (string) $par);
     }
     # Don't let the user get stuck with a certain date
     if ($opts->getValue('offset') || $opts->getValue('dir') == 'prev') {
         $opts->setValue('year', '');
         $opts->setValue('month', '');
     }
     // If the user doesn't have the right permission to view the specific
     // log type, throw a PermissionsError
     // If the log type is invalid, just show all public logs
     $type = $opts->getValue('type');
     if (!LogPage::isLogType($type)) {
         $opts->setValue('type', '');
     } elseif (isset($wgLogRestrictions[$type]) && !$this->getUser()->isAllowed($wgLogRestrictions[$type])) {
         throw new PermissionsError($wgLogRestrictions[$type]);
     }
     # Handle type-specific inputs
     $qc = array();
     if ($opts->getValue('type') == 'suppress') {
         $offender = User::newFromName($opts->getValue('offender'), false);
         if ($offender && $offender->getId() > 0) {
             $qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId());
         } elseif ($offender && IP::isIPAddress($offender->getName())) {
             $qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName());
         }
     }
     # Some log types are only for a 'User:' title but we might have been given
     # only the username instead of the full title 'User:username'. This part try
     # to lookup for a user by that name and eventually fix user input. See bug 1697.
     wfRunHooks('GetLogTypesOnUser', array(&$this->typeOnUser));
     if (in_array($opts->getValue('type'), $this->typeOnUser)) {
         # ok we have a type of log which expect a user title.
         $target = Title::newFromText($opts->getValue('page'));
         if ($target && $target->getNamespace() === NS_MAIN) {
             # User forgot to add 'User:', we are adding it for him
             $opts->setValue('page', Title::makeTitleSafe(NS_USER, $opts->getValue('page')));
         }
     }
     $this->show($opts, $qc);
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:60,代码来源:SpecialLog.php

示例9: wfWikiaAbortAutoblock

function wfWikiaAbortAutoblock($autoblockip, $block)
{
    if (!IP::isPublic($autoblockip)) {
        wfDebug("IP {$autoblockip} was prevented from being autoblocked by internal IP autoblock");
        return false;
    }
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:7,代码来源:Block.php

示例10: save

 public function save()
 {
     wfProfileIn(__METHOD__);
     $action = "";
     if ($this->data['type'] & self::TYPE_USER && User::isIP($this->data['text'])) {
         $this->data['ip_hex'] = IP::toHex($this->data['text']);
     }
     $dbw = wfGetDB(DB_MASTER, array(), $this->wg->ExternalSharedDB);
     if (empty($this->data['id'])) {
         /* add block */
         $dbw->insert($this->db_table, $this->mapToDB(), __METHOD__);
         $action = 'add';
     } else {
         $dbw->update($this->db_table, $this->mapToDB(), array('p_id' => $this->data['id']), __METHOD__);
         $action = 'edit';
     }
     if ($dbw->affectedRows()) {
         if ($action == 'add') {
             $this->data['id'] = $dbw->insertId();
         }
         $this->log($action);
     } else {
         $action = '';
     }
     $dbw->commit();
     wfProfileOut(__METHOD__);
     return $action ? $this->data['id'] : false;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:28,代码来源:Phalanx.class.php

示例11: getClientIP

 /**
  * Get IP
  *
  * @access	public
  * @return	string
  */
 public static function getClientIP()
 {
     if (self::$ClientIP !== FALSE) {
         return self::$ClientIP;
     }
     $CieIP = (isset($_SERVER['HTTP_CLIENT_IP']) and $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
     $RemIP = (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
     $ForIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
     if ($CieIP && $RemIP) {
         self::$ClientIP = $CieIP;
     } elseif ($RemIP) {
         self::$ClientIP = $RemIP;
     } elseif ($CieIP) {
         self::$ClientIP = $CieIP;
     } elseif ($ForIP) {
         self::$ClientIP = $ForIP;
     }
     if (strstr(self::$ClientIP, ',')) {
         $x = explode(',', self::$ClientIP);
         self::$ClientIP = end($x);
     }
     // checked IP address
     $CheckIP = new IPValidator();
     if (!$CheckIP->isValid(self::$ClientIP)) {
         self::$ClientIP = '0.0.0.0';
     }
     unset($CheckIP);
     unset($CieIP);
     unset($RemIP);
     unset($ForIP);
     return self::$ClientIP;
 }
开发者ID:DevSKolb,项目名称:FLOWLite,代码行数:38,代码来源:IP.php

示例12: execute

 public function execute($sub)
 {
     global $wgOut, $wgRequest;
     global $wgLandingPageBase, $wgChapterLandingPages, $wgLandingPageDefaultTarget;
     $lang = preg_match('/^[A-Za-z-]+$/', $wgRequest->getVal('lang')) ? $wgRequest->getVal('lang') : 'en';
     $utm_source = $wgRequest->getVal('utm_source');
     $utm_medium = $wgRequest->getVal('utm_medium');
     $utm_campaign = $wgRequest->getVal('utm_campaign');
     $referrer = $wgRequest->getHeader('referer');
     $target = $wgRequest->getVal('target', null);
     if (!$target) {
         $target = $wgLandingPageDefaultTarget;
     }
     $tracking = '?' . wfArrayToCGI(array('utm_source' => "{$utm_source}", 'utm_medium' => "{$utm_medium}", 'utm_campaign' => "{$utm_campaign}", 'referrer' => "{$referrer}", 'target' => "{$target}"));
     $ip = $wgRequest->getVal('ip') ? $wgRequest->getVal('ip') : wfGetIP();
     if (IP::isValid($ip)) {
         $country = geoip_country_code_by_name($ip);
         if (is_string($country) && array_key_exists($country, $wgChapterLandingPages)) {
             $wgOut->redirect($this->getDestination($utm_source) . '/' . $wgChapterLandingPages[$country] . $tracking);
             return;
         }
     }
     // No valid IP or chapter page - let's just go for the passed in url or our fallback
     if (Http::isValidURI($target)) {
         $wgOut->redirect($target . '/' . $lang . $tracking);
         return;
     } else {
         $wgOut->redirect($wgLandingPageBase . $target . '/' . $lang . $tracking);
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:30,代码来源:GeoLite_body.php

示例13: credit

 /**
  *
  * @param string $name
  * @param int $amount
  * @return boolean false if failed
  */
 private function credit($name = null, $amount = 0)
 {
     $output = $this->getOutput();
     $output->addWikiText("=== Credit (name, amount) ===");
     $output->addWikiText("name = {$name}");
     $output->addWikiText("amount = {$amount}");
     $user = User::newFromName($name);
     if (!$user || $user->getId() == 0) {
         $output->addWikiText("=== ERROR: Invalid UserName ===");
         return false;
     }
     $output->addWikiText("=== User ===");
     $output->addWikiText("user_id = " . $user->getId());
     $output->addWikiText("user_name = " . $user->getName());
     $output->addWikiText("user_realname = " . $user->getRealName());
     $output->addWikiText("user_email = " . $user->getEmail());
     $output->addWikiText("=== Transaction ===");
     $output->addWikiText("True balance before = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     if (!is_int($amount) || $amount <= 0 || $amount > 1000) {
         $output->addWikiText("=== ERROR: Invalid Amount ===");
         return false;
     }
     $tmr = array('tmr_type' => TM_REFUND_TYPE, 'tmr_user_id' => $user->getId(), 'tmr_mail' => $user->getEmail(), 'tmr_ip' => IP::sanitizeIP(wfGetIP()), 'tmr_amount' => $amount, 'tmr_currency' => 'EUR', 'tmr_desc' => 'tm-refund', 'tmr_status' => 'OK');
     wfRunHooks('CreateTransaction', array(&$tmr));
     $output->addWikiText("==== DONE ====");
     $output->addWikiText("True balance after = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     $output->addWikiText("== SUCCESS ==");
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:34,代码来源:SpecialTransactionsAdmin.php

示例14: execute

 public function execute()
 {
     $dbw = wfGetDB(DB_MASTER);
     // Perform this in a transaction so an failed load doesn't erase current data.
     $dbw->begin();
     // Clear existing GeoIP data.
     try {
         $dbw->delete('geoip', '*', __METHOD__);
     } catch (DBQueryError $e) {
         $this->error('ERROR: Could not delete existing geographic data. Is the GeoIP schema loaded?', true);
     }
     // Load fresh data from the first (and only) argument.
     $filename = $this->getArg(0);
     $lines = exec('wc -l ' . $filename);
     $handle = fopen($filename, 'r');
     $count = 0;
     while (($data = fgetcsv($handle, 256, ',')) !== false) {
         // Output a nice progress bar.
         if ($count % 1000 == 0) {
             $progress = ceil($count / $lines * 50);
             $this->output('[' . str_repeat('=', $progress) . str_repeat(' ', 50 - $progress) . '] ' . ceil($count / $lines * 100) . '%' . "\r");
         }
         ++$count;
         $record = array('begin_ip_long' => IP::toUnsigned($data[0]), 'end_ip_long' => IP::toUnsigned($data[1]), 'country_code' => $data[4]);
         $dbw->insert('geoip', $record, __METHOD__);
     }
     $this->output("\n");
     $dbw->commit();
     $this->output('Successfully loaded ' . $count . ' geographic IP ranges.' . "\n");
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:30,代码来源:RebuildGeoIP.php

示例15: trySubmit

 function trySubmit()
 {
     global $wgOut, $wgUser;
     $errors = array();
     $ip = $this->mUnblockIP;
     if (!IP::isIPAddress($ip) && strlen($ip)) {
         $errors[] = array('globalblocking-unblock-ipinvalid', $ip);
         $ip = '';
     }
     if (0 == ($id = GlobalBlocking::getGlobalBlockId($ip))) {
         $errors[] = array('globalblocking-notblocked', $ip);
     }
     if (count($errors) > 0) {
         return $errors;
     }
     $dbw = GlobalBlocking::getGlobalBlockingMaster();
     $dbw->delete('globalblocks', array('gb_id' => $id), __METHOD__);
     $page = new LogPage('gblblock');
     $page->addEntry('gunblock', Title::makeTitleSafe(NS_USER, $ip), $this->mReason);
     $successmsg = wfMsgExt('globalblocking-unblock-unblocked', array('parse'), $ip, $id);
     $wgOut->addHTML($successmsg);
     $link = $wgUser->getSkin()->makeKnownLinkObj(SpecialPage::getTitleFor('GlobalBlockList'), wfMsg('globalblocking-return'));
     $wgOut->addHTML($link);
     $wgOut->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
     return array();
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:26,代码来源:SpecialRemoveGlobalBlock.php


注:本文中的IP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。