Skip to content

Instantly share code, notes, and snippets.

@meowmanijado
Created July 20, 2017 05:27
Show Gist options
  • Save meowmanijado/4f236bfd4533a490486e0a9c30108a82 to your computer and use it in GitHub Desktop.
Save meowmanijado/4f236bfd4533a490486e0a9c30108a82 to your computer and use it in GitHub Desktop.
Regex for http_referer
<?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