本文整理汇总了PHP中validate_ip函数的典型用法代码示例。如果您正苦于以下问题:PHP validate_ip函数的具体用法?PHP validate_ip怎么用?PHP validate_ip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate_ip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateUrl
/**
* Returns whether a URL is in a correct format or not
*
* @param string URL to be tested
* @return bool
* @author Christian Hoffmann
* @author Froxlor team <team@froxlor.org> (2010-)
*
*/
function validateUrl($url)
{
global $idna_convert, $theme;
if (strtolower(substr($url, 0, 7)) != "http://" && strtolower(substr($url, 0, 8)) != "https://") {
$url = 'http://' . $url;
}
// needs converting
$url = $idna_convert->encode($url);
$pattern = "/^https?:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,4}(\\:[0-9]+)?\\/?(.+)?\$/i";
if (preg_match($pattern, $url)) {
return true;
}
// not an fqdn
if (strtolower(substr($url, 0, 7)) == "http://" || strtolower(substr($url, 0, 8)) == "https://") {
if (strtolower(substr($url, 0, 7)) == "http://") {
$ip = strtolower(substr($url, 7));
}
if (strtolower(substr($url, 0, 8)) == "https://") {
$ip = strtolower(substr($url, 8));
}
$ip = substr($ip, 0, strpos($ip, '/'));
// possible : in IP (when a port is given), #1173
// but only if there actually IS ONE
if (strpos($ip, ':') !== false) {
$ip = substr($ip, 0, strpos($ip, ':'));
}
if (validate_ip($ip, true) !== false) {
return true;
} else {
return false;
}
} else {
return false;
}
}
示例2: validateUrl
/**
* Returns whether a URL is in a correct format or not.
*
* @param string URL to be tested
*
* @return bool
*
* @author Christian Hoffmann
*/
function validateUrl($url)
{
if (strtolower(substr($url, 0, 7)) != 'http://' && strtolower(substr($url, 0, 8)) != 'https://') {
$url = 'http://' . $url;
}
if (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) !== false) {
return true;
} else {
if (strtolower(substr($url, 0, 7)) == 'http://' || strtolower(substr($url, 0, 8)) == 'https://') {
if (strtolower(substr($url, 0, 7)) == 'http://') {
$ip = strtolower(substr($url, 7));
}
if (strtolower(substr($url, 0, 8)) == 'https://') {
$ip = strtolower(substr($url, 8));
}
$ip = substr($ip, 0, strpos($ip, '/'));
if (validate_ip($ip, true) !== false) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
示例3: validateUrl
/**
* Returns whether a URL is in a correct format or not
*
* @param string URL to be tested
* @return bool
* @author Christian Hoffmann
*
*/
function validateUrl($url)
{
global $idna_convert;
if (strtolower(substr($url, 0, 7)) != "http://" && strtolower(substr($url, 0, 8)) != "https://") {
$url = 'http://' . $url;
}
// needs converting
$url = $idna_convert->encode($url);
$pattern = "/^https?:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,4}(\\:[0-9]+)?\\/?(.+)?\$/i";
if (preg_match($pattern, $url)) {
return true;
}
// not an fqdn
if (strtolower(substr($url, 0, 7)) == "http://" || strtolower(substr($url, 0, 8)) == "https://") {
if (strtolower(substr($url, 0, 7)) == "http://") {
$ip = strtolower(substr($url, 7));
}
if (strtolower(substr($url, 0, 8)) == "https://") {
$ip = strtolower(substr($url, 8));
}
$ip = substr($ip, 0, strpos($ip, '/'));
if (validate_ip($ip, true) !== false) {
return true;
} else {
return false;
}
} else {
return false;
}
}
示例4: checkMysqlAccessHost
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
*
* @version $Id$
*/
function checkMysqlAccessHost($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
$mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
foreach ($mysql_access_host_array as $host_entry) {
if (validate_ip($host_entry, true) == false && validateDomain($host_entry) == false && $host_entry != '%') {
return array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'invalidmysqlhost', $host_entry);
}
}
return array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
}
示例5: forwarded_ip
function forwarded_ip()
{
$keys = array("HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_FORWARDED_FOR", "HTTP_FORWARDED", "HTTP_CLIENT_IP", "HTTP_X_CLUSTER_CLIENT_IP");
foreach ($keys as $key) {
if (isset($_SERVER[$key])) {
$ip_array = explode(",", $_SERVER[$key]);
foreach ($ip_array as $ip) {
$ip = trim($ip);
if (validate_ip($ip)) {
return $ip;
}
}
}
}
return "";
}
示例6: forwarded_ip
function forwarded_ip()
{
$keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT-IP');
foreach ($keys as $key) {
if (isset($_SERVER[$key])) {
$ip_array = explode(',', $_SERVER[$key]);
foreach ($ip_array as $ip) {
$ip = trim($ip);
if (validate_ip($ip)) {
return $ip;
}
}
}
}
return '';
}
示例7: getIpAddress1
public function getIpAddress1()
{
$ip_keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($ip_keys as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
// trim for safety measures
$ip = trim($ip);
// attempt to validate IP
if (validate_ip($ip)) {
return $ip;
}
}
}
}
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
}
示例8: get_ip_address
function get_ip_address()
{
$IP_Keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($IP_Keys as $Key) {
if (array_key_exists($Key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$Key]) as $IP) {
// trim for safety measures.
$IP = trim($IP);
// attempt to validate IP.
if (validate_ip($IP)) {
return $IP;
}
}
}
}
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
}
示例9: get_ip_address
function get_ip_address()
{
// check for shared internet/ISP IP
if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
// check for IPs passing through proxies
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// check if multiple ips exist in var
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($iplist as $ip) {
if (validate_ip($ip)) {
return $ip;
}
}
} else {
if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED'])) {
return $_SERVER['HTTP_X_FORWARDED'];
}
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
}
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) {
return $_SERVER['HTTP_FORWARDED_FOR'];
}
if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED'])) {
return $_SERVER['HTTP_FORWARDED'];
}
// return unreliable ip since all else failed
echo $_SERVER['REMOTE_ADDR'];
return $_SERVER['REMOTE_ADDR'];
}
示例10: AddBan
function AddBan($nickname, $type, $steam, $ip, $length, $dfile, $dname, $reason, $fromsub)
{
$objResponse = new xajaxResponse();
global $userbank, $username;
if (!$userbank->HasAccess(ADMIN_OWNER | ADMIN_ADD_BAN)) {
$objResponse->redirect("index.php?p=login&m=no_access", 0);
$log = new CSystemLog("w", "Ошибка доступа", $username . " пытался добавить бан, не имея на то прав.");
return $objResponse;
}
$steam = trim($steam);
$error = 0;
// If they didnt type a steamid
if (empty($steam) && $type == 0) {
$error++;
$objResponse->addAssign("steam.msg", "innerHTML", "Введите Steam ID или Community ID");
$objResponse->addScript("\$('steam.msg').setStyle('display', 'block');");
} else {
if ($type == 0 && !is_numeric($steam) && !validate_steam($steam) || is_numeric($steam) && (strlen($steam) < 15 || !validate_steam($steam = FriendIDToSteamID($steam)))) {
$error++;
$objResponse->addAssign("steam.msg", "innerHTML", "Введите действительный Steam ID или Community ID");
$objResponse->addScript("\$('steam.msg').setStyle('display', 'block');");
} else {
if (empty($ip) && $type == 1) {
$error++;
$objResponse->addAssign("ip.msg", "innerHTML", "Введите IP");
$objResponse->addScript("\$('ip.msg').setStyle('display', 'block');");
} else {
if ($type == 1 && !validate_ip($ip)) {
$error++;
$objResponse->addAssign("ip.msg", "innerHTML", "Введите действительный IP");
$objResponse->addScript("\$('ip.msg').setStyle('display', 'block');");
} else {
$objResponse->addAssign("steam.msg", "innerHTML", "");
$objResponse->addScript("\$('steam.msg').setStyle('display', 'none');");
$objResponse->addAssign("ip.msg", "innerHTML", "");
$objResponse->addScript("\$('ip.msg').setStyle('display', 'none');");
}
}
}
}
if ($error > 0) {
return $objResponse;
}
$nickname = RemoveCode($nickname);
$ip = preg_replace('#[^\\d\\.]#', '', $ip);
//strip ip of all but numbers and dots
$dname = RemoveCode($dname);
$reason = RemoveCode($reason);
if (!$length) {
$len = 0;
} else {
$len = $length * 60;
}
// prune any old bans
PruneBans();
if ((int) $type == 0) {
// Check if the new steamid is already banned
$chk = $GLOBALS['db']->GetRow("SELECT count(bid) AS count FROM " . DB_PREFIX . "_bans WHERE authid = ? AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemovedBy IS NULL AND type = '0'", array($steam));
if (intval($chk[0]) > 0) {
$objResponse->addScript("ShowBox('Ошибка', 'SteamID: {$steam} уже забанен.', 'red', '');");
return $objResponse;
}
// Check if player is immune
$admchk = $userbank->GetAllAdmins();
foreach ($admchk as $admin) {
if ($admin['authid'] == $steam && $userbank->GetProperty('srv_immunity') < $admin['srv_immunity']) {
$objResponse->addScript("ShowBox('Ошибка', 'SteamID админа " . $admin['user'] . " ({$steam}) под иммунитетом.', 'red', '');");
return $objResponse;
}
}
}
if ((int) $type == 1) {
$chk = $GLOBALS['db']->GetRow("SELECT count(bid) AS count FROM " . DB_PREFIX . "_bans WHERE ip = ? AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemovedBy IS NULL AND type = '1'", array($ip));
if (intval($chk[0]) > 0) {
$objResponse->addScript("ShowBox('Ошибка', 'Этот IP ({$ip}) уже забанен.', 'red', '');");
return $objResponse;
}
}
$pre = $GLOBALS['db']->Prepare("INSERT INTO " . DB_PREFIX . "_bans(created,type,ip,authid,name,ends,length,reason,aid,adminIp ) VALUES\r\n\t\t\t\t\t\t\t\t\t(UNIX_TIMESTAMP(),?,?,?,?,(UNIX_TIMESTAMP() + ?),?,?,?,?)");
$GLOBALS['db']->Execute($pre, array($type, $ip, $steam, $nickname, $length * 60, $len, $reason, $userbank->GetAid(), $_SERVER['REMOTE_ADDR']));
$subid = $GLOBALS['db']->Insert_ID();
if ($dname && $dfile) {
$GLOBALS['db']->Execute("INSERT INTO " . DB_PREFIX . "_demos(demid,demtype,filename,origname)\r\n\t\t\t\t\t\t VALUES(?,'B', ?, ?)", array((int) $subid, $dfile, $dname));
}
if ($fromsub) {
$submail = $GLOBALS['db']->Execute("SELECT name, email FROM " . DB_PREFIX . "_submissions WHERE subid = '" . (int) $fromsub . "'");
// Send an email when ban is accepted
$requri = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], ".php") + 4);
$headers = 'From: submission@' . $_SERVER['HTTP_HOST'] . "\n" . 'X-Mailer: PHP/' . phpversion();
$message = "Привет,\n";
$message .= "Ваша заявка на бан подтверждена админом.\nПерейдите по ссылке, чтобы посмотреть банлист.\n\nhttp://" . $_SERVER['HTTP_HOST'] . $requri . "?p=banlist";
mail($submail->fields['email'], "[SourceBans] Бан добавлен", $message, $headers);
$GLOBALS['db']->Execute("UPDATE `" . DB_PREFIX . "_submissions` SET archiv = '2', archivedby = '" . $userbank->GetAid() . "' WHERE subid = '" . (int) $fromsub . "'");
}
$GLOBALS['db']->Execute("UPDATE `" . DB_PREFIX . "_submissions` SET archiv = '3', archivedby = '" . $userbank->GetAid() . "' WHERE SteamId = ?;", array($steam));
$kickit = isset($GLOBALS['config']['config.enablekickit']) && $GLOBALS['config']['config.enablekickit'] == "1";
if ($kickit) {
$objResponse->addScript("ShowKickBox('" . ((int) $type == 0 ? $steam : $ip) . "', '" . (int) $type . "');");
} else {
$objResponse->addScript("ShowBox('Бан добавлен', 'Бан успешно добавлен', 'green', 'index.php?p=admin&c=bans');");
//.........这里部分代码省略.........
示例11: trim
$SID = -1;
} else {
$SteamID = trim(htmlspecialchars($_POST['SteamID']));
$BanIP = trim(htmlspecialchars($_POST['BanIP']));
$PlayerName = htmlspecialchars($_POST['PlayerName']);
$BanReason = htmlspecialchars($_POST['BanReason']);
$SubmitterName = htmlspecialchars($_POST['SubmitName']);
$Email = trim(htmlspecialchars($_POST['EmailAddr']));
$SID = (int) $_POST['server'];
$validsubmit = true;
$errors = "";
if (strlen($SteamID) != 0 && $SteamID != "STEAM_0:" && !validate_steam($SteamID)) {
$errors .= '* Please type a valid STEAM ID.<br>';
$validsubmit = false;
}
if (strlen($BanIP) != 0 && !validate_ip($BanIP)) {
$errors .= '* Please type a valid IP-address.<br>';
$validsubmit = false;
}
if (strlen($PlayerName) == 0) {
$errors .= '* You must include a player name<br>';
$validsubmit = false;
}
if (strlen($BanReason) == 0) {
$errors .= '* You must include comments<br>';
$validsubmit = false;
}
if (!check_email($Email)) {
$errors .= '* You must include a valid email address<br>';
$validsubmit = false;
}
示例12: status_message
status_message('begin', $lng['install']['testing_new_db']);
$db = new db($mysql_host, $mysql_unpriv_user, $mysql_unpriv_pass, $mysql_database);
status_message('green', 'OK');
status_message('begin', $lng['install']['importing_data']);
$db_schema = './syscp.sql';
$sql_query = @file_get_contents($db_schema, 'r');
$sql_query = remove_remarks($sql_query);
$sql_query = split_sql_file($sql_query, ';');
for ($i = 0; $i < sizeof($sql_query); ++$i) {
if (trim($sql_query[$i]) != '') {
$result = $db->query($sql_query[$i]);
}
}
status_message('green', 'OK');
status_message('begin', 'System Servername...');
if (validate_ip($_SERVER['SERVER_NAME'], true) !== false) {
status_message('red', $lng['install']['servername_should_be_fqdn']);
} else {
status_message('green', 'OK');
}
//now let's change the settings in our settings-table
status_message('begin', $lng['install']['changing_data']);
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = 'admin@" . $db->escape($servername) . "' WHERE `settinggroup` = 'panel' AND `varname` = 'adminmail'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($serverip) . "' WHERE `settinggroup` = 'system' AND `varname` = 'ipaddress'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($servername) . "' WHERE `settinggroup` = 'system' AND `varname` = 'hostname'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($dbversion) . "' WHERE `settinggroup` = 'system' AND `varname` = 'dbversion'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($languages[$language]) . "' WHERE `settinggroup` = 'panel' AND `varname` = 'standardlanguage'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($mysql_access_host) . "' WHERE `settinggroup` = 'system' AND `varname` = 'mysql_access_host'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($webserver) . "' WHERE `settinggroup` = 'system' AND `varname` = 'webserver'");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . "` SET `value` = '" . $db->escape($webserver) . "' WHERE `settinggroup` = 'system' AND `varname` = 'webserver'");
//FIXME
示例13: _insertAllowedTransfers
private function _insertAllowedTransfers($domainid)
{
$ins_stmt = $this->pdns_db->prepare("\n\t\t\tINSERT INTO domainmetadata set `domain_id` = :did, `kind` = 'ALLOW-AXFR-FROM', `content` = :value\n\t\t");
$ins_data = array('did' => $domainid);
if (count($this->_ns) > 0 || count($this->_axfr) > 0) {
// put nameservers in allow-transfer
if (count($this->_ns) > 0) {
foreach ($this->_ns as $ns) {
foreach ($ns["ips"] as $ip) {
$ins_data['value'] = $ip;
$ins_stmt->execute($ins_data);
}
}
}
// AXFR server #100
if (count($this->_axfr) > 0) {
foreach ($this->_axfr as $axfrserver) {
if (validate_ip($axfrserver, true) !== false) {
$ins_data['value'] = $axfrserver;
$ins_stmt->execute($ins_data);
}
}
}
}
}
示例14:
if (strlen($_POST['password']) > 100) {
$errors[] = 'Your password must be less than 100 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required.';
}
if (user_email_exist($_POST['email']) === true) {
$errors[] = 'That email address is already in use.';
}
if ($_POST['selected'] != 1) {
$errors[] = 'You are only allowed to have an account if you accept the rules.';
}
if (validate_ip(getIP()) === false && $config['validate_IP'] === true) {
$errors[] = 'Failed to recognize your IP address. (Not a valid IPv4 address).';
}
}
}
?>
<h1>Register Account</h1>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
if ($config['mailserver']['register']) {
?>
<h1>Email authentication required</h1>
<p>We have sent you an email with an activation link to your submitted email address.</p>
<p>If you can't find the email within 5 minutes, check your junk/trash inbox as it may be mislocated there.</p>
<?php
} else {
示例15: _generateDomainConfig
private function _generateDomainConfig($domain = array())
{
if (isset($domain['froxlorhost']) && $domain['froxlorhost'] === '1') {
$froxlorhost = true;
} else {
$froxlorhost = false;
}
$bindconf_file = '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
$bindconf_file .= 'zone "' . $domain['domain'] . '" in {' . "\n";
$bindconf_file .= ' type master;' . "\n";
$bindconf_file .= ' file "' . makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']) . '";' . "\n";
$bindconf_file .= ' allow-query { any; };' . "\n";
if (count($this->nameservers) > 0 || count($this->axfrservers) > 0) {
// open allow-transfer
$bindconf_file .= ' allow-transfer {' . "\n";
// put nameservers in allow-transfer
if (count($this->nameservers) > 0) {
foreach ($this->nameservers as $ns) {
$bindconf_file .= ' ' . $ns['ip'] . ';' . "\n";
}
}
// AXFR server #100
if (count($this->axfrservers) > 0) {
foreach ($this->axfrservers as $axfrserver) {
if (validate_ip($axfrserver, true) !== false) {
$bindconf_file .= ' ' . $axfrserver . ';' . "\n";
}
}
}
// close allow-transfer
$bindconf_file .= ' };' . "\n";
}
$bindconf_file .= '};' . "\n";
$bindconf_file .= "\n";
return $bindconf_file;
}