PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] Log errors for specific IP while monitoring incoming 404 and redirect

 March 12, 2022     error-handling, php, wordpress     No comments   

Issue

I have a plugin installed on my WordPress website that logs 404 and redirect to similar pages. Here is the part of the plugin that does the logging is below:

function log($query){
        
    if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
        ini_set( 'error_log', WP_CONTENT_DIR . '/redirect.txt' );
    }
        
    if(empty($query['settings']['log']) || !WP_DEBUG || !WP_DEBUG_LOG)
        return;
        
    $request_url = home_url() . $query['request']['url'];
    $redirect = $query['redirect']['url'];    
    $ip = $_SERVER['REMOTE_ADDR'];
        
    error_log('//' . $ip . '//' . $request_url . '//' . $redirect . '//');
        
} 

I would like to log error for only specific incoming IP, for example, I want to log error for only 111.11.111.11. Other IPs should be ignored.

How can incorporate that into the code above


Solution

you can do like this

    $request_url = home_url() . $query['request']['url'];
    $redirect = $query['redirect']['url'];    
    $ip = $_SERVER['REMOTE_ADDR'];
    
    if ($ip == '111.11.111.11') {
         error_log('//' . $ip . '//' . $request_url . '//' . $redirect . '//');
    }


Answered By - Abhi747
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing