Created
July 20, 2017 05:27
-
-
Save meowmanijado/4f236bfd4533a490486e0a9c30108a82 to your computer and use it in GitHub Desktop.
Regex for http_referer
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 | |
// get host name from URL | |
preg_match('@^(?:http://)?(?:https://)?([^/]+)@i', | |
$_SERVER['HTTP_REFERER'], $matches); | |
$hosts = $matches[1]; | |
// get last two segments of host name | |
preg_match('/[^.]+\.[^.]+$/', $hosts, $matches); | |
var_dump($matches[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment