- var_dump: documentation ( source)
- strpos: documentation ( source)
- parse_url: documentation ( source)
- in_array: documentation ( source)
<?php
function urlWhitelisted($url)
{
$always_allowed = array('localhost');
$whitelisted_domains = array('fxnetworks.com') + $always_allowed;
$domain = parse_url($url);
var_dump($domain);
if (strpos($url, "/") === 0 || in_array($domain, $whitelisted_domains)) {
return true;
}
foreach ($whitelisted_domains as $whitelisted_domain) {
$whitelisted_domain = '.' . $whitelisted_domain;
if (strpos($domain, $whitelisted_domain) === (strlen($domain) - strlen($whitelisted_domain))) {
return true;
}
}
return false;
}
$domains = array('/user', 'localhost/user', 'http://localhost:4039', 'http://fxnetworks.com/user', 'http://google.com', 'google.com', 'fxnetworks.com.google.com');
foreach($domains as $domain) {
var_dump(urlWhitelisted($domain));
}