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


PHP short_ipv6函数代码示例

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


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

示例1: session_create


//.........这里部分代码省略.........
					LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
					WHERE u.user_id = ' . (int) $bot;
            }
            $result = $db->sql_query($sql);
            $this->data = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        if ($this->data['user_id'] != ANONYMOUS && !$bot) {
            $this->data['session_last_visit'] = isset($this->data['session_time']) && $this->data['session_time'] ? $this->data['session_time'] : ($this->data['user_lastvisit'] ? $this->data['user_lastvisit'] : time());
        } else {
            $this->data['session_last_visit'] = $this->time_now;
        }
        // Force user id to be integer...
        $this->data['user_id'] = (int) $this->data['user_id'];
        // At this stage we should have a filled data array, defined cookie u and k data.
        // data array should contain recent session info if we're a real user and a recent
        // session exists in which case session_id will also be set
        // Is user banned? Are they excluded? Won't return on ban, exists within method
        if ($this->data['user_type'] != USER_FOUNDER) {
            if (!$config['forwarded_for_check']) {
                $this->check_ban($this->data['user_id'], $this->ip);
            } else {
                $ips = explode(' ', $this->forwarded_for);
                $ips[] = $this->ip;
                $this->check_ban($this->data['user_id'], $ips);
            }
        }
        $this->data['is_registered'] = !$bot && $this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER) ? true : false;
        $this->data['is_bot'] = $bot ? true : false;
        // If our friend is a bot, we re-assign a previously assigned session
        if ($this->data['is_bot'] && $bot == $this->data['user_id'] && $this->data['session_id']) {
            // Only assign the current session if the ip, browser and forwarded_for match...
            if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) {
                $s_ip = short_ipv6($this->data['session_ip'], $config['ip_check']);
                $u_ip = short_ipv6($this->ip, $config['ip_check']);
            } else {
                $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $config['ip_check']));
                $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $config['ip_check']));
            }
            $s_browser = $config['browser_check'] ? trim(strtolower(substr($this->data['session_browser'], 0, 149))) : '';
            $u_browser = $config['browser_check'] ? trim(strtolower(substr($this->browser, 0, 149))) : '';
            $s_forwarded_for = $config['forwarded_for_check'] ? substr($this->data['session_forwarded_for'], 0, 254) : '';
            $u_forwarded_for = $config['forwarded_for_check'] ? substr($this->forwarded_for, 0, 254) : '';
            if ($u_ip === $s_ip && $s_browser === $u_browser && $s_forwarded_for === $u_forwarded_for) {
                $this->session_id = $this->data['session_id'];
                // Only update session DB a minute or so after last update or if page changes
                if ($this->time_now - $this->data['session_time'] > 60 || $this->update_session_page && $this->data['session_page'] != $this->page['page']) {
                    $this->data['session_time'] = $this->data['session_last_visit'] = $this->time_now;
                    $sql_ary = array('session_time' => $this->time_now, 'session_last_visit' => $this->time_now, 'session_admin' => 0);
                    if ($this->update_session_page) {
                        $sql_ary['session_page'] = substr($this->page['page'], 0, 199);
                        $sql_ary['session_forum_id'] = $this->page['forum'];
                    }
                    $this->update_session($sql_ary);
                    // Update the last visit time
                    $sql = 'UPDATE ' . USERS_TABLE . '
						SET user_lastvisit = ' . (int) $this->data['session_time'] . '
						WHERE user_id = ' . (int) $this->data['user_id'];
                    $db->sql_query($sql);
                }
                $SID = '?sid=';
                $_SID = '';
                return true;
            } else {
                // If the ip and browser does not match make sure we only have one bot assigned to one session
                $db->sql_query('DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $this->data['user_id']);
开发者ID:Alexey3112,项目名称:phpbb,代码行数:67,代码来源:session.php

示例2: _ipCheck

/**
* Check IPs for match
*
* Checks a portion (or the entire) IP to determine if they match
*
* @param    string  $stored_ip  source IP address
* @param    string  $remote_ip  remote IP address
* @param    int     $force      true - force IP check regardless of
*                               configuration setting
* @return   boolean true on match / false on mis-match
*
*/
function _ipCheck($stored_ip, $remote_ip, $force = 0)
{
    global $_CONF;
    if ($_CONF['session_ip_check'] == 0 && $force == 0) {
        return true;
    }
    if ($force) {
        $ipLength = 3;
    } else {
        $ipLength = $_CONF['session_ip_check'] + 1;
    }
    if (strpos($remote_ip, ':') !== false && strpos($stored_ip, ':') !== false) {
        $s_ip = short_ipv6($stored_ip, $ipLength);
        $r_ip = short_ipv6($remote_ip, $ipLength);
    } else {
        $s_ip = implode('.', array_slice(explode('.', $stored_ip), 0, $ipLength));
        $r_ip = implode('.', array_slice(explode('.', $remote_ip), 0, $ipLength));
    }
    if ($r_ip === $s_ip) {
        return true;
    }
    return false;
}
开发者ID:spacequad,项目名称:glfusion,代码行数:35,代码来源:lib-sessions.php

示例3: insert_ip

/**
* Log IPs and optionally block and/or ban the "fake" IP
*
* Inserts "real" and "fake" IPs in SPECULATIVE_TABLE, blocks and/or bans the "fake" IP session if configured to do so.
* On External IPs (log) page, the first column shows the "fake IP address" and the third column shows the "real IP address".
* The reason we do it in this way is because when you're looking at the IP address of a post, you're going to see the "fake IP address".
*
* We use $db->sql_escape() in all our SQL statements rather than str_replace("\'","''",$_REQUEST['var']) on each var as it comes in.
* This is to avoid confusion and to avoid escaping the same text twice and ending up with too many backslshes in the final result.
*
* @param	string	$ip_masked		The "fake" IP address.
* @param	int		$mode		The test mode used (modes defined in constants.php).
* @param	string	$ip_direct		The "real" IP address.
* @param	string	$info			Additional info like User-Agent string or CGI-Proxy URL(s) - optional.
*/
function insert_ip($ip_masked, $mode, $ip_direct, $info = '')
{
    global $phpbb_root_path, $phpEx;
    global $db, $sid, $key, $config;
    // We don't check $ip_direct as it has just been validated (top of the script) in the case of plugins, or '0.0.0.0' for TOR_DNSEL/PROXY_DNSBL.
    // We also don't validate $ip_masked in the case of X_FORWARDED_FOR as that is actually the IP requesting this page (already validated up top)
    if ($mode != X_FORWARDED_FOR && !preg_match(get_preg_expression('ipv4'), $ip_masked) && !preg_match(get_preg_expression('ipv6'), $ip_masked)) {
        return;
        // contains invalid data, return and don't log anything
    }
    // Validate IP length according to admin ("Session IP Validation" in ACP->Server Configuration->Security Settings)
    // session_begin() looks at $config['ip_check'] to see which bits of an IP address to check and so shall we.
    // First, check if both addresses are IPv6, else we assume both are IPv4 ($f_ip is the fake, $r_ip is the real)
    if (strpos($ip_masked, ':') !== false && strpos($ip_direct, ':') !== false) {
        // short_ipv6() from includes/functions.php
        $f_ip = short_ipv6($ip_masked, $config['ip_check']);
        $r_ip = short_ipv6($ip_direct, $config['ip_check']);
    } else {
        $f_ip = implode('.', array_slice(explode('.', $ip_masked), 0, $config['ip_check']));
        $r_ip = implode('.', array_slice(explode('.', $ip_direct), 0, $config['ip_check']));
    }
    // If "Session IP Validation" is NOT set to None, and the validated length matches, we return and log nothing
    //  (see "Select ip validation" in includes/acp/acp_board.php for more info)
    if ($config['ip_check'] != 0 && $r_ip === $f_ip) {
        return;
    }
    /**
     * In Java, at least, there's a possibility that the main IP we're recording and the "masked" IP address are the same.
     * the reason this function would be called, in those cases, is to log $lan_ip.   $lan_ip, however, isn't reliable enough
     * to block people over (assuming any blocking is taking place).  As such, although we log it, we don't update phpbb_sessions.
     */
    if ($mode != JAVA_INTERNAL) {
        /**
         * session_speculative_test will eventually be used to determine whether or not this session ought to be blocked.
         * This check is done by performing a bitwise "and" against $config['ip_block'].  If the bits that represent the various
         * modes 'and' with any of the bits in the bitwise representation of session_speculative_test, a block is done.
         * To guarantee that each bit is unique to a specific mode, powers of two are used to represent the modes (see constants.php).
         */
        $sql = 'UPDATE ' . SESSIONS_TABLE . " \n\t\t\tSET session_speculative_test = session_speculative_test | " . $db->sql_escape($mode) . " \n\t\t\tWHERE session_id = '" . $db->sql_escape($sid) . "' \n\t\t\t\tAND session_speculative_key = '" . $db->sql_escape($key) . "'";
        if (!($result = $db->sql_query($sql))) {
            die;
        }
        // if neither the session_id or the session_speculative_key are valid (as would be revealed by $db->sql_affectedrows being 0),
        // we assume the information is not trustworthy and quit.
        if (!$db->sql_affectedrows($result)) {
            die;
        }
        // Ban if appropriate
        if ($config['ip_ban'] && $mode & $config['ip_block']) {
            // $ban_len takes precedence over $ban_len_other unless $ban_len is set to "-1" (other - until $ban_len_other)
            // see function user_ban() in functions_user.php for more info
            $ban_len = $config['ip_ban_length'];
            $ban_len_other = $config['ip_ban_length_other'];
            $ban_exclude = 0;
            $ban_reason = $config['ip_ban_reason'];
            $ban_give_reason = $config['ip_ban_give_reason'];
            // user_ban() function from includes/functions_user.php
            include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            user_ban('ip', $ip_masked, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
        }
    }
    // Fetch currently logged entries for the specified IPs/method. Prevent duplicate entries.
    $sql = 'SELECT * FROM ' . SPECULATIVE_TABLE . " \n\t\tWHERE ip_address = '" . $db->sql_escape($ip_masked) . "' \n\t\t\tAND method = " . $db->sql_escape($mode) . " \n\t\t\tAND real_ip = '" . $db->sql_escape($ip_direct) . "'";
    // Allows duplicate logs of Masked/Real-IP/Method combination if the User-Agent (Browser/Plugin info) differs.
    if ($config['ip_log_agent_check'] && $mode != XSS && !empty($info)) {
        $sql .= " AND info = '" . $db->sql_escape($info) . "'";
    }
    $result = $db->sql_query($sql);
    if (!($row = $db->sql_fetchrow($result))) {
        $sql_ary = array('ip_address' => $ip_masked, 'method' => $mode, 'discovered' => time(), 'real_ip' => $ip_direct, 'info' => $info);
        $sql = 'INSERT INTO ' . SPECULATIVE_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
        $db->sql_query($sql);
    }
}
开发者ID:codegooglecom,项目名称:proxy-revealer,代码行数:89,代码来源:probe.php

示例4: session_begin


//.........这里部分代码省略.........
             if (stripos($ip, '::ffff:') === 0) {
                 $ipv4 = substr($ip, 7);
                 if (preg_match($format_ipv4, $ipv4)) {
                     $ip = $ipv4;
                 }
             }
             $this->ip = $ip;
         } else {
             // We want to use the last valid address in the chain
             // Leave foreach loop when address is invalid
             break;
         }
     }
     $this->load = false;
     // Load limit check (if applicable)
     if ($config['limit_load'] || $config['limit_search_load']) {
         if (function_exists('sys_getloadavg') && ($load = sys_getloadavg()) || ($load = explode(' ', @file_get_contents('/proc/loadavg')))) {
             $this->load = array_slice($load, 0, 1);
             $this->load = floatval($this->load[0]);
         } else {
             set_config('limit_load', '0');
             set_config('limit_search_load', '0');
         }
     }
     // if session id is set
     if (!empty($this->session_id)) {
         $sql = "SELECT u.*, s.*\n\t\t\t\tFROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u\n\t\t\t\tWHERE s.session_id = '" . $db->sql_escape($this->session_id) . "'\n\t\t\t\t\tAND u.user_id = s.session_user_id";
         $result = $db->sql_query($sql);
         $this->data = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);
         // Did the session exist in the DB?
         if (isset($this->data['user_id'])) {
             if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) {
                 $s_ip = short_ipv6($this->data['session_ip'], $config['ip_check']);
                 $u_ip = short_ipv6($this->ip, $config['ip_check']);
             } else {
                 $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $config['ip_check']));
                 $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $config['ip_check']));
             }
             $s_browser = $config['browser_check'] ? trim(strtolower(substr($this->data['session_browser'], 0, 254))) : '';
             $u_browser = $config['browser_check'] ? trim(strtolower(substr($this->browser, 0, 254))) : '';
             // referer checks
             // The @ before $config['referer_validation'] suppresses notices present while running the updater
             $check_referer_path = @$config['referer_validation'] == REFERER_VALIDATE_PATH;
             $referer_valid = true;
             // we assume HEAD and TRACE to be foul play and thus only whitelist GET
             if (@$config['referer_validation'] && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) !== 'get') {
                 $referer_valid = $this->validate_referer($check_referer_path);
             }
             if ($u_ip === $s_ip && $s_browser === $u_browser && $referer_valid) {
                 // Some useful boolean checks... defined here for future easy of use
                 $session_expired = false;
                 $session_refresh_time = (int) SESSION_REFRESH;
                 $autologin_expired = !empty($config['max_autologin_time']) && $this->data['session_time'] < $this->time_now - 86400 * (int) $config['max_autologin_time'] + $session_refresh_time ? true : false;
                 $session_time_expired = $this->data['session_time'] < $this->time_now - ((int) $config['session_length'] + $session_refresh_time) ? true : false;
                 $session_refresh = $this->data['session_time'] < $this->time_now - $session_refresh_time ? true : false;
                 if (!$session_expired) {
                     // Check the session length timeframe if autologin is not enabled.
                     // Else check the autologin length... and also removing those having autologin enabled but no longer allowed site-wide.
                     if (empty($this->data['session_autologin'])) {
                         if ($session_time_expired) {
                             $session_expired = true;
                         }
                     } elseif (empty($config['allow_autologin']) || $autologin_expired) {
                         $session_expired = true;
                     }
开发者ID:ALTUN69,项目名称:icy_phoenix,代码行数:67,代码来源:sessions.php


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