3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_valid_time_domain( $url ) { $whitelisted_domains = array( 'mydomain.com', 'mydomain.net' ); $domain = parse_url( $url, PHP_URL_HOST ); // Check if we match the domain exactly if ( in_array( $domain, $whitelisted_domains ) ) { return true; } foreach( $whitelisted_domains as $whitelisted_domain ) { $whitelisted_domain = '.' . $whitelisted_domain; // Prevent things like 'evilsitetime.com' if( strpos( $domain, $whitelisted_domain ) === ( strlen( $domain ) - strlen( $whitelisted_domain ) ) ) { return true; break; } } return false; } $domains = array( 'http://mydomain.com', 'http://www.mydomain.com', 'http://mydomain.com.evilsite.com', 'http://mydomain.com.mydomain.net', 'http://evilsitemydomain.com', 'http://mydomain.com.evil%45site.com', 'http://evil%45sitemydomain.com', 'http://evil%00sitemydomain.com', 'http://mydomain.com.evil%00site.com','http://evilsite.com/.mydomain.com', 'http://mydomain.com%00.evilsite.com', 'http://evilsite.com#.mydomain.com', 'http://evilsite.com@mydomain.com', 'http://mydomain.com@evilsite.com', 'http://evilsite.com#@mydomain.com', 'http://evilsite.com:mydomain.com', 'file://stuff@myfile:mydomain.net', 'file:///dev@mydomain.net', 'file:///dev?@mydomain.net', 'file:///dev?mydomain.net', 'http:mydomain.net', 'http:evilsite.com//mydomain.net'); foreach( $domains as $domain ) { echo $domain . "\n"; var_dump( is_valid_time_domain( $domain ) ); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
http://mydomain.com bool(true) http://www.mydomain.com bool(true) http://mydomain.com.evilsite.com bool(false) http://mydomain.com.mydomain.net bool(true) http://evilsitemydomain.com bool(false) http://mydomain.com.evil%45site.com bool(false) http://evil%45sitemydomain.com bool(false) http://evil%00sitemydomain.com bool(false) http://mydomain.com.evil%00site.com bool(false) http://evilsite.com/.mydomain.com bool(false) http://mydomain.com%00.evilsite.com bool(false) http://evilsite.com#.mydomain.com bool(false) http://evilsite.com@mydomain.com bool(true) http://mydomain.com@evilsite.com bool(false) http://evilsite.com#@mydomain.com bool(false) http://evilsite.com:mydomain.com bool(false) file://stuff@myfile:mydomain.net bool(false) file:///dev@mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) file:///dev?@mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) file:///dev?mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) http:mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) http:evilsite.com//mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 http://mydomain.com bool(true) http://www.mydomain.com bool(true) http://mydomain.com.evilsite.com bool(false) http://mydomain.com.mydomain.net bool(true) http://evilsitemydomain.com bool(false) http://mydomain.com.evil%45site.com bool(false) http://evil%45sitemydomain.com bool(false) http://evil%00sitemydomain.com bool(false) http://mydomain.com.evil%00site.com bool(false) http://evilsite.com/.mydomain.com bool(false) http://mydomain.com%00.evilsite.com bool(false) http://evilsite.com#.mydomain.com bool(false) http://evilsite.com@mydomain.com bool(true) http://mydomain.com@evilsite.com bool(false) http://evilsite.com#@mydomain.com bool(false) http://evilsite.com:mydomain.com bool(false) file://stuff@myfile:mydomain.net bool(false) file:///dev@mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) file:///dev?@mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) file:///dev?mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) http:mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false) http:evilsite.com//mydomain.net Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/dYLWg on line 13 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/dYLWg on line 13 bool(false)
Output for 5.3.3 - 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
http://mydomain.com bool(true) http://www.mydomain.com bool(true) http://mydomain.com.evilsite.com bool(false) http://mydomain.com.mydomain.net bool(true) http://evilsitemydomain.com bool(false) http://mydomain.com.evil%45site.com bool(false) http://evil%45sitemydomain.com bool(false) http://evil%00sitemydomain.com bool(false) http://mydomain.com.evil%00site.com bool(false) http://evilsite.com/.mydomain.com bool(false) http://mydomain.com%00.evilsite.com bool(false) http://evilsite.com#.mydomain.com bool(false) http://evilsite.com@mydomain.com bool(true) http://mydomain.com@evilsite.com bool(false) http://evilsite.com#@mydomain.com bool(false) http://evilsite.com:mydomain.com bool(false) file://stuff@myfile:mydomain.net bool(false) file:///dev@mydomain.net bool(false) file:///dev?@mydomain.net bool(false) file:///dev?mydomain.net bool(false) http:mydomain.net bool(false) http:evilsite.com//mydomain.net bool(false)
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.2
http://mydomain.com bool(true) http://www.mydomain.com bool(true) http://mydomain.com.evilsite.com bool(false) http://mydomain.com.mydomain.net bool(true) http://evilsitemydomain.com bool(false) http://mydomain.com.evil%45site.com bool(false) http://evil%45sitemydomain.com bool(false) http://evil%00sitemydomain.com bool(false) http://mydomain.com.evil%00site.com bool(false) http://evilsite.com/.mydomain.com bool(false) http://mydomain.com%00.evilsite.com bool(false) http://evilsite.com#.mydomain.com bool(false) http://evilsite.com@mydomain.com bool(true) http://mydomain.com@evilsite.com bool(false) http://evilsite.com#@mydomain.com bool(false) http://evilsite.com:mydomain.com Warning: parse_url(http://evilsite.com:mydomain.com): Unable to parse URL in /in/dYLWg on line 4 bool(false) file://stuff@myfile:mydomain.net Warning: parse_url(file://stuff@myfile:mydomain.net): Unable to parse URL in /in/dYLWg on line 4 bool(false) file:///dev@mydomain.net bool(false) file:///dev?@mydomain.net bool(false) file:///dev?mydomain.net bool(false) http:mydomain.net bool(false) http:evilsite.com//mydomain.net bool(false)
Output for 5.1.2 - 5.1.6
http://mydomain.com bool(true) http://www.mydomain.com bool(true) http://mydomain.com.evilsite.com bool(false) http://mydomain.com.mydomain.net bool(true) http://evilsitemydomain.com bool(false) http://mydomain.com.evil%45site.com bool(false) http://evil%45sitemydomain.com bool(false) http://evil%00sitemydomain.com bool(false) http://mydomain.com.evil%00site.com bool(false) http://evilsite.com/.mydomain.com bool(false) http://mydomain.com%00.evilsite.com bool(false) http://evilsite.com#.mydomain.com bool(false) http://evilsite.com@mydomain.com bool(true) http://mydomain.com@evilsite.com bool(false) http://evilsite.com#@mydomain.com bool(false) http://evilsite.com:mydomain.com Warning: parse_url(http://evilsite.com:mydomain.com): Unable to parse url in /in/dYLWg on line 4 bool(false) file://stuff@myfile:mydomain.net Warning: parse_url(file://stuff@myfile:mydomain.net): Unable to parse url in /in/dYLWg on line 4 bool(false) file:///dev@mydomain.net bool(false) file:///dev?@mydomain.net bool(false) file:///dev?mydomain.net bool(false) http:mydomain.net bool(false) http:evilsite.com//mydomain.net 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
http://mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://www.mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com.evilsite.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com.mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsitemydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com.evil%45site.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evil%45sitemydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evil%00sitemydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com.evil%00site.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsite.com/.mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com%00.evilsite.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsite.com#.mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsite.com@mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://mydomain.com@evilsite.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsite.com#@mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http://evilsite.com:mydomain.com Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) file://stuff@myfile:mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) file:///dev@mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) file:///dev?@mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) file:///dev?mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http:mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false) http:evilsite.com//mydomain.net Notice: Use of undefined constant PHP_URL_HOST - assumed 'PHP_URL_HOST' in /in/dYLWg on line 4 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/dYLWg on line 4 bool(false)

preferences:
316.5 ms | 414 KiB | 459 Q