Last active
April 16, 2021 08:44
-
-
Save codetot/c82dcf88756773a48ee5e8f5f02576f7 to your computer and use it in GitHub Desktop.
Capture matching User Agent WordPress with domain name to process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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