Created
August 1, 2023 21:06
-
-
Save zidansec/8d204ae136a922949824bc8bde613792 to your computer and use it in GitHub Desktop.
Simple PHP code for parsing domains, automatically fetching the TLD of the domain or subdomain.
This file contains 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
function get_domain($url) { | |
$str = '/^(?:https?.\/\/)?(?:[^@\/\n]+@)?(?:)?([^:\/?\n]+).*/m'; | |
preg_match_all($str, $url, $matches, PREG_SET_ORDER, 0); | |
foreach ($matches as $key => $value) { | |
// code... | |
//var_dump($value); | |
return $value[1]; | |
} | |
} | |
// get_domain("https://www.domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); | |
echo get_domain("https://www.domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // www.domain.com | |
echo get_domain("https://domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // domain.com | |
echo get_domain("http://www.domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // www.domain.com | |
echo get_domain("http://domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // domain.com | |
echo get_domain("www.domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // www.domain.com | |
echo get_domain("domain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // domain.com | |
echo get_domain("www.dom-ain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // www.dom-ain.com | |
echo get_domain("dom-ain.com/login/admin.php?login&username=admin&password=admin&submit=login"); // dom-ain.com | |
echo get_domain("https://www.domain.com/demo/assets/css/"); // www.domain.com | |
echo get_domain("https://domain.com/demo/assets/css/"); // domain.com | |
echo get_domain("http://www.domain.com/demo/assets/css/"); // www.domain.com | |
echo get_domain("http://domain.com/demo/assets/css/"); // domain.com | |
echo get_domain("www.domain.com/demo/assets/css/"); // www.domain.com | |
echo get_domain("domain.com/demo/assets/css/"); // domain.com | |
echo get_domain("www.dom-ain.com/demo/assets/css/"); // www.dom-ain.com | |
echo get_domain("dom-ain.com/demo/assets/css/"); // dom-ain.com | |
echo get_domain("https://www.domain.com"); // www.domain.com | |
echo get_domain("https://domain.com"); // domain.com | |
echo get_domain("http://www.domain.com"); // www.domain.com | |
echo get_domain("http://domain.com"); // domain.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment