Skip to content

Instantly share code, notes, and snippets.

@codetot
Last active April 16, 2021 08:44
Show Gist options
  • Select an option

  • Save codetot/c82dcf88756773a48ee5e8f5f02576f7 to your computer and use it in GitHub Desktop.

Select an option

Save codetot/c82dcf88756773a48ee5e8f5f02576f7 to your computer and use it in GitHub Desktop.

Revisions

  1. @codetot-tech codetot-tech revised this gist Apr 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wordpress-user-agent-regex.php
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@

    preg_match('/(WordPress\/\d\.\d.\d;)[ ]{1,}(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?((?:[\w-]+\.)+[\w-]+)/', $request_user_agent, $matches);

    var_dump($matches[3]);
    var_dump($matches[3]); // domain.com
  2. @codetot-tech codetot-tech created this gist Apr 16, 2021.
    8 changes: 8 additions & 0 deletions wordpress-user-agent-regex.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <?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]);