Search code examples
phpw3cw3c-validationbots

How to detect the w3.org's bot in PHP?


I would like to detect w3c validator's bot in PHP. So if somebody try to validate my site on http://validator.w3.org , I would like to do something else in Php.


Solution

  • function w3c(){
    if((stristr($_SERVER["HTTP_USER_AGENT"],'w3c') === TRUE))
    return true;
    }
    
    if(w3c()){
        // this is the w3c
    }
    

    And if you want to hide something from the w3c validator just use:

    if(!w3c()){
        // this is not visible for the w3c validator
    }