Skip to content

Instantly share code, notes, and snippets.

@codetot
Last active April 16, 2021 08:44
Show Gist options
  • Save codetot/c82dcf88756773a48ee5e8f5f02576f7 to your computer and use it in GitHub Desktop.
Save codetot/c82dcf88756773a48ee5e8f5f02576f7 to your computer and use it in GitHub Desktop.
Capture matching User Agent WordPress with domain name to process
<?php
// Example User-Agent: WordPress 5.7.1; http://domain.com
$request_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? false;
preg_match('/(WordPress\/\d\.\d.\d;)[ ]{1,}(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?((?:[\w-]+\.)+[\w-]+)/', $request_user_agent, $matches);
var_dump($matches[3]); // domain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment