3

isagent

is_agent
SYNOPSIS

is_agent($s, $agent=false)

CODE
  1. function is_agent($s, $agent=false) {
  2.     if (!$agent) {
  3.         require_once 'useragent.php';
  4.  
  5.         $agent=user_agent();
  6.     }
  7.  
  8.     return $agent and preg_match('/'. $s . '/i', $agent);
  9. }
is_opengraph
SYNOPSIS

is_opengraph($agent=false)

DESCRIPTION

is_opengraph returns true if $agent is the name of an agent capable of reading Open Graph tags. By default, if $agent is false, is_opengraph tests the value returned by user_agent.

CODE
  1. function is_opengraph($agent=false) {
  2.     $bots = array(
  3.         'facebookexternalhit',
  4.         'facebot',
  5.         'google',
  6.         'twitterbot',
  7.         'linkedinbot',
  8.         'pinterest',
  9.     );
  10.  
  11.     return is_agent(implode('|', $bots), $agent);
  12. }
is_bot
SYNOPSIS

is_bot($agent=false)

DESCRIPTION

is_bot returns true if $agent is the name of a search engine agent. By default, if $agent is false, is_bot tests the value returned by user_agent.

CODE
  1. function is_bot($agent=false){
  2.     $bots = array(
  3.         'googlebot',
  4.         'bingbot',
  5.         'yahoo! slurp',
  6.         'baiduspider',
  7.         'yandexbot',
  8.     );
  9.  
  10.     return is_agent(implode('|', $bots), $agent);
  11. }
SEE ALSO

useragent

Comments

To add a comment, click here.