午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    discuz論壇使用cdn后無(wú)法獲取用戶真實(shí)ip的解決方法
    來(lái)源:易賢網(wǎng) 閱讀:807 次 日期:2016-06-21 08:57:01
    溫馨提示:易賢網(wǎng)小編為您整理了“discuz論壇使用cdn后無(wú)法獲取用戶真實(shí)ip的解決方法”,方便廣大網(wǎng)友查閱!

    該問(wèn)題存在于任何cdn產(chǎn)品,如果您使用了cdn產(chǎn)品,該discuz方法都適用。

    該問(wèn)題導(dǎo)致的結(jié)果:

    1.discuz論壇可能無(wú)法獲得用戶的真實(shí)ip,導(dǎo)致某些用戶ip顯示的是加速樂(lè)節(jié)點(diǎn)的ip

    2.論壇訪問(wèn)量過(guò)大的話,可能會(huì)導(dǎo)致用戶訪問(wèn)時(shí)提示“抱歉,您的 ip 地址不在被允許,或您的賬號(hào)被禁用,無(wú)法訪問(wèn)本站點(diǎn)”

    產(chǎn)生原因:

    使用cdn,對(duì)于網(wǎng)站訪客來(lái)說(shuō),相當(dāng)于使用了代理訪問(wèn),而discuz在設(shè)計(jì)上,是優(yōu)先獲取代理ip,其它才會(huì)檢測(cè)代理服務(wù)器是否將用戶真實(shí)ip傳輸過(guò)來(lái),也就是說(shuō)獲取代理ip優(yōu)先于用戶真實(shí)ip。如果您的網(wǎng)站不需要對(duì)用戶訪問(wèn)做過(guò)多的限制,強(qiáng)烈建議按照以下方法進(jìn)行:

    解決方法(discuz x2):

    打開(kāi)discuz /source/class/class_core.php 文件

    找到第341行,或者搜索“http_client_ip”,找到如下代碼:

    代碼如下:

    function _get_client_ip() {

    $ip = $_server['remote_addr'];

    if (isset($_server['http_client_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_client_ip'])) {

    $ip = $_server['http_client_ip'];

    } elseif(isset($_server['http_x_forwarded_for']) and preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_server['http_x_forwarded_for'], $matches)) {

    foreach ($matches[0] as $xip) {

    if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {

    $ip = $xip;

    break;

    }

    }

    }

    return $ip;

    }

    將以上代碼修改為:

    代碼如下:

    function _get_client_ip() {

    $ip = $_server['remote_addr'];

    if (isset($_server['http_x_real_forwarded_for']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_x_real_forwarded_for'])) {

    $ip = $_server['http_x_real_forwarded_for'];

    }

    elseif (isset($_server['http_x_forwarded_for']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_x_forwarded_for'])) {

    $ip = $_server['http_x_forwarded_for'];

    }

    elseif (isset($_server['http_client_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_client_ip'])) {

    $ip = $_server['http_client_ip'];

    }

    return $ip;

    }

    解決方法(discuz x2.5)

    打開(kāi)文件\source\class\discuz\discuz_application.php 找到如下代碼:

    代碼如下:

    private function _get_client_ip() {

    $ip = $_server['remote_addr'];

    if (isset($_server['http_client_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_client_ip'])) {

    $ip = $_server['http_client_ip'];

    } elseif(isset($_server['http_x_forwarded_for']) and preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_server['http_x_forwarded_for'], $matches)) {

    foreach ($matches[0] as $xip) {

    if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {

    $ip = $xip;

    break;

    }

    }

    }

    return $ip;

    }

    將其修改為:

    代碼如下:

    private function _get_client_ip() {

    $ip = $_server['remote_addr'];

    if (isset($_server['http_x_real_forwarded_for']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_x_real_forwarded_for'])) {

    $ip = $_server['http_x_real_forwarded_for'];

    }

    elseif (isset($_server['http_x_forwarded_for']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_x_forwarded_for'])) {

    $ip = $_server['http_x_forwarded_for'];

    }

    elseif (isset($_server['http_client_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_client_ip'])) {

    $ip = $_server['http_client_ip'];

    }

    return $ip;

    }

    以上操作后,登陸cdn后臺(tái)和你的discuz論壇后臺(tái)分別清除緩存即可。

    更多信息請(qǐng)查看CMS教程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!
    相關(guān)閱讀CMS教程

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)