3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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)); }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(1) { ["path"]=> string(5) "/user" } bool(true) array(1) { ["path"]=> string(14) "localhost/user" } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false) array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(9) "localhost" ["port"]=> int(4039) } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false) array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(14) "fxnetworks.com" ["path"]=> string(5) "/user" } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false) array(2) { ["scheme"]=> string(4) "http" ["host"]=> string(10) "google.com" } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false) array(1) { ["path"]=> string(10) "google.com" } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false) array(1) { ["path"]=> string(25) "fxnetworks.com.google.com" } Warning: strpos() expects parameter 1 to be string, array given in /in/H2pNe on line 17 Warning: strlen() expects parameter 1 to be string, array given in /in/H2pNe on line 17 bool(false)
Output for 4.3.0 - 5.2.17
array(1) { ["path"]=> string(5) "/user" } bool(true) array(1) { ["path"]=> string(14) "localhost/user" } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false) array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(9) "localhost" ["port"]=> int(4039) } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false) array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(14) "fxnetworks.com" ["path"]=> string(5) "/user" } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false) array(2) { ["scheme"]=> string(4) "http" ["host"]=> string(10) "google.com" } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false) array(1) { ["path"]=> string(10) "google.com" } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false) array(1) { ["path"]=> string(25) "fxnetworks.com.google.com" } Notice: Array to string conversion in /in/H2pNe on line 17 Notice: Array to string conversion in /in/H2pNe on line 17 bool(false)