xxxxxxxxxx
$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
echo $parse['host']; // prints 'google.com'
xxxxxxxxxx
// Warning: This can be manipulated by hackers!
// If this is problematic, store the domain in a config file
$currentDomain = $_SERVER['SERVER_NAME'];
xxxxxxxxxx
$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//It is absolutely necessary to sanitize both values and
// do proper input validation (CWE-20).
//They must not be used in any security context.