3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(1) { ["path"]=> string(5) "/user" } bool(true) array(1) { ["path"]=> string(14) "localhost/user" } Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in /in/H2pNe:17 Stack trace: #0 /in/H2pNe(17): strpos(Array, '.fxnetworks.com') #1 /in/H2pNe(28): urlWhitelisted('localhost/user') #2 {main} thrown in /in/H2pNe on line 17
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.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)

preferences:
215.09 ms | 405 KiB | 343 Q