• albertof

    (@albertof)


    Hi I am using your plugin on HTTPS. I am not sure if this issue is related to HTTPS anyway the logged IP is always the same for every download. I have enabled do not count downloads from Bots. Log unique IP is disabled. Please help

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi,

    I have enabled do not count downloads from Bots. Log unique IP is disabled.

    Can you check Enable Debug under the Settings tab. Then carry out a test. Once you have completed the test, can you check the log file. Report back with any findings in the log file.

    Thank you

    Thread Starter albertof

    (@albertof)

    Hi,

    Thank you for your reply.
    I’ve enabled Debug saved changes and trigger some downloads. After that the log was empty. So I reset the log file and triggered some other download. this time the log was only containing the following:

    2020-03-02 21:43:40: Log has been reset.
    ——————————————————-

    The downloads are anchor links with href of the type:

    href=”/?smd_process_download=1&download_id=2705″>setup.msi…

    The download counter is incremented but other information are missing.
    From Log table:

    /media/setup.msi 172.16.0.1 2020-03-02 21:46:12 Not Logged In

    If you need more informations please let me know.
    Thank you.
    Alberto

    • This reply was modified 5 years ago by albertof.
    • This reply was modified 5 years ago by albertof.
    • This reply was modified 5 years ago by albertof.
    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi,

    In regards to your download file, did you add the full URL path? For example: https://yoursite.com/media/file-name.

    Regards

    Thread Starter albertof

    (@albertof)

    Hi all,

    To respond to your question the address is relative. Anyway I did some more research based on the fact that my WP is hosted on azure and probably find the cause of the issue:

    In the Azure Application Gateway, the http header field called ‘Remote_Addr’ does not contains the actual public IP address instead it contains the private IP address of Azure Application Gateway.

    The header field that contains the IP address of the incoming request is changed to ‘x-forwarded-for’.

    It could be possible to test first this field before querying the Remote_Addr field?

    Thanks

    Thread Starter albertof

    (@albertof)

    Some more information:

    article:

    https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-faq

    Application Gateway inserts x-forwarded-for, x-forwarded-proto, and x-forwarded-port headers into the request forwarded to the backend. The format for x-forwarded-for header is a comma-separated list of IP:Port. The valid values for x-forwarded-proto are http or https. X-forwarded-port specifies the port at which the request reached at the Application Gateway

    Thanks.

    Thread Starter albertof

    (@albertof)

    Hi all,

    for those have the same issue of same IP download in Azure I realised the fix:
    Update the following function:

    function sdm_get_ip_address( $ignore_private_and_reserved = false ) {
        $flags = $ignore_private_and_reserved ? (FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) : 0;
        foreach ( array( 'HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
    	if ( array_key_exists( $key, $_SERVER ) === true ) {
    	    foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
    		$ip = trim( $ip ); // just to be safe
    
    		if ( !empty( $ip ) ) {
    			$parsed_url = parse_url( $ip );
    			$host = $parsed_url['host'];
    			if ( isset( $host ) ) {
    				if ( filter_var( $host, FILTER_VALIDATE_IP, $flags ) !== false ) {
    		 		   return $host;
    				}
    			}
    		}
    	    }
    	}
        }
        return null;
    }

    Now is working on my Azure WP installation.
    Alberto

    • This reply was modified 5 years ago by albertof.
    Plugin Contributor mbrsolution

    (@mbrsolution)

    Thank you Alberto for sharing your fix.

    Just to verify with you, your fix is only related to your host or can this solution be used with other host?

    I will also make a note of this for future reference.

    Thank you

    Thread Starter albertof

    (@albertof)

    Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘The logged IP is always the same’ is closed to new replies.