Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
Log errors for specific IP while monitoring incoming 404 and redirect

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

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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 . '//');
    }
over 4 years ago · Santiago Trujillo Relatório

0

You can define an array that contains the IP addresses to which you intend to support the logging, like:

$logips = ['111.11.111.11'];

and then check whether the IP address is inside that array:

if (in_array($_SERVER['REMOTE_ADDR'], $logips)) {
    error_log('//' . $ip . '//' . $request_url . '//' . $redirect . '//');
}

This way you will be able to just modify the content of the array whenever new IP addresses are to be added or old IP addresses are to be removed, while the logic will remain reliable. Also, it is recommendable to make this an application setting, because that tester/developer might have other special behaviors at other parts of the application as well.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda