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 git.master, git.master_jit, rfc.property-hooks
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)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
135.89 ms | 409 KiB | 8 Q