3v4l.org

run code in 300+ PHP versions simultaneously
<?php function urlWhitelisted($url) { $always_allowed = array('localhost'); $whitelisted_domains = array_merge(array('fxnetworks.com'), $always_allowed); var_dump($whitelisted_domains); if (strpos($url, "/") !== 0 && strpos($url, "http") !== 0) { $url = 'http://' . $url; } $domain = parse_url($url, PHP_URL_HOST); 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.1.2 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 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(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } NULL bool(true) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(9) "localhost" bool(true) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(9) "localhost" bool(true) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(14) "fxnetworks.com" bool(true) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(10) "google.com" bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(10) "google.com" bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } string(25) "fxnetworks.com.google.com" 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.1
array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(true) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false) array(2) { [0]=> string(14) "fxnetworks.com" [1]=> string(9) "localhost" } Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/fUdAZ on line 12 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/fUdAZ on line 12 NULL bool(false)

preferences:
267.11 ms | 406 KiB | 459 Q