Illegal websites should not initiate any form of manual service requests to our staff. It is strictly prohibited to use honmau Media's technical support services and products to engage in any illegal activities. If discovered, no technical support will be provided.×
Current location:home> news > help and support

Discuz! X3.5 How to get real IP in the forum after using cdn

Tips before viewing: ModifydiscuzNot the best way to get real IP

If you have the ability, it is recommended to learn about Apache mod_remoteip, Nginx ngx_http_realip_module or other similar features

Configuring on the server side allows your server access log to collect the correct IP

Before modifying using this tutorial, please make sure that X3.5 can currently obtain a real IP address

If you can already obtain the real IP address, do not refer to this tutorial to modify it!

First open the file config/config_global.php and find this line:

$_config['security']['onlyremoteaddr'] = 1;

Change 1 to 0

Then go to the bottom position and find this paragraph:

// ------------------------- CONFIG IPGETTER -------------------------- //

$_config['ipgetter']['setting'] = '';

$_config['ipgetter']['header']['header'] = 'HTTP_X_FORWARDED_FOR'

of which

$_config['ipgetter']['setting'] = '';

changed to

$_config['ipgetter']['setting'] = 'header';

(If it is already a header, there is no need to change it)

For many CDNs, you can already obtain the real IP by doing this step. You can try it.

On the premise of completing the previous step, if your CDN falls within the following scope, you can further refer to the following content to try to modify it and observe the IP obtained

Correct or more accurate results can often be obtained after further modification as follows

(The following information comes from the official documents of major manufacturers. Whether it is available depends on the accuracy of the manufacturer's documents. It is recommended to test it yourself after modification)

What needs to be revised is this line:

$_config['ipgetter']['header']['header'] = 'HTTP_X_FORWARDED_FOR';

Cloudflare:

changed to

$_config['ipgetter']['header']['header'] = 'HTTP_CF_CONNECTING_IP';

Alibaba Cloud:

Option 1: Change to

$_config['ipgetter']['header']['header'] = 'HTTP_ALI_CDN_REAL_IP';

Option 2:

(This is modified depending on the situation and may not be available)

https://help.aliyun.com/document_detail/155768.html

Refer to the configuration example 2 at the bottom of this article

Configuration scenario: Add the client's real IP information to the source and pass the client's IP address information to the source station.

Configuration method:

Custom request header name: X-Real-IP.

Request header parameter: $remote_addr.

After configuration, change the above line to

$_config['ipgetter']['header']['header'] = 'HTTP_X_REAL_IP';

Tencent Cloud:

https://cloud.tencent.com/document/product/228/45078

Refer to this article to modify the configuration of Tencent Cloud

Set the header parameter to: X-Client-IP

Set the header value to: $client_ip

After configuration, change the above line to

$_config['ipgetter']['header']['header'] = 'HTTP_X_CLIENT_IP';

Another cloud:

changed to

$_config['ipgetter']['header']['header'] = 'HTTP_X_REAL_IP';

Fastly:

changed to

$_config['ipgetter']['header']['header'] = 'HTTP_FASTLY_CLIENT_IP';

Azure:

changed to

$_config['ipgetter']['header']['header'] = 'HTTP_X_AZURE_CLIENTIP';

Due to the large number of CDN manufacturers, it is impossible to list them one by one, and this part of the functions still need to be further improved

After the Discuz part is configured and can be used smoothly, if your site does not use stand-alone mode, you need to configure the UCenter Server accordingly.

Go to the uc_server/data/config.inc.php file and find the following paragraph: (To use the custom path uc, you need to change uc_server to your own real uc location)

(Early X3.5 versions may not have it, but you can add it yourself at the end of the file)

define('UC_ONLYREMOTEADDR', 1);

define('UC_IPGETTER', 'header');

define('UC_IPGETTER_HEADER', serialize(array('header' => 'HTTP_X_FORWARDED_FOR')));

Change 1 in the UC_ONLYREMOTEADDR line to 0.

The HTTP_X_FORWARDED_FOR in the UC_IPGETTER_HEADER line can also be modified to the value you need as you modify Discuz above (don't care if you haven't changed above)

Special safety tips:

$_config['security']['onlyremoteaddr'] = 1;

After changing this line in the configuration file to 0, you must definitely check carefully whether the ipgetter is filled in correctly

If you forget to write, although it can also allow you to obtain the user IP, it will cause the website to unconditionally trust the IP information sent by the user.

Hackers can take the opportunity to fake their IP into arbitrary values, which will have a great impact on the security of your site!

Be sure to pay attention to this!

------------------------

afterhonmau MediaTest: After some users modified the above code, they tested and registered their forum accounts and found that the IP registered by the user was still displayed as the IP of cdn.

Open the website directory:/source/class/discuz/discuz_application.php file and find the return $ip; method, as follows:

20240527161110

Replace the following code

if (isset($_SERVER['HTTP_X_REAL_IP'])){

$ip = $_SERVER['HTTP_X_REAL_IP'];

}

return $ip;

20240527161302

After modifying the above code, go to the background to update the cache, and re-test whether the registered account is a local IP.

© Website copyright and disclaimer

1.[honmau Media] independently owns the copyright of all materials on relevant pages of this website;

2. No one is allowed to copy it without the express written permission of [honmau Media];

3. The articles that do not indicate "honmau Media" on this website are all from the Internet and are only for everyone to learn and refer;

4. If there is any infringement/violation/irregularity, please contact customer service QQ or email to delete it, please understand;

5.[honmau Media] reserves the right to correct, modify and update this statement at any time.legal notice

Message Board
* Contact customer service for urgent issues
submitted
submission
Working days: 8:30 - 22:00 Online QQ

customer service

Company Introduction
top