Changeset 42343 for trunk/src/wp-includes/class-http.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-http.php
r42208 r42343 29 29 30 30 // Aliases for HTTP response codes. 31 const HTTP_CONTINUE 32 const SWITCHING_PROTOCOLS 33 const PROCESSING 34 const EARLY_HINTS 35 36 const OK 37 const CREATED 38 const ACCEPTED 39 const NON_AUTHORITATIVE_INFORMATION 40 const NO_CONTENT 41 const RESET_CONTENT 42 const PARTIAL_CONTENT 43 const MULTI_STATUS 44 const IM_USED 45 46 const MULTIPLE_CHOICES 47 const MOVED_PERMANENTLY 48 const FOUND 49 const SEE_OTHER 50 const NOT_MODIFIED 51 const USE_PROXY 52 const RESERVED 53 const TEMPORARY_REDIRECT 54 const PERMANENT_REDIRECT 31 const HTTP_CONTINUE = 100; 32 const SWITCHING_PROTOCOLS = 101; 33 const PROCESSING = 102; 34 const EARLY_HINTS = 103; 35 36 const OK = 200; 37 const CREATED = 201; 38 const ACCEPTED = 202; 39 const NON_AUTHORITATIVE_INFORMATION = 203; 40 const NO_CONTENT = 204; 41 const RESET_CONTENT = 205; 42 const PARTIAL_CONTENT = 206; 43 const MULTI_STATUS = 207; 44 const IM_USED = 226; 45 46 const MULTIPLE_CHOICES = 300; 47 const MOVED_PERMANENTLY = 301; 48 const FOUND = 302; 49 const SEE_OTHER = 303; 50 const NOT_MODIFIED = 304; 51 const USE_PROXY = 305; 52 const RESERVED = 306; 53 const TEMPORARY_REDIRECT = 307; 54 const PERMANENT_REDIRECT = 308; 55 55 56 56 const BAD_REQUEST = 400; … … 148 148 public function request( $url, $args = array() ) { 149 149 $defaults = array( 150 'method' => 'GET',150 'method' => 'GET', 151 151 /** 152 152 * Filters the timeout value for an HTTP request. … … 157 157 * Default 5. 158 158 */ 159 'timeout' => apply_filters( 'http_request_timeout', 5 ),159 'timeout' => apply_filters( 'http_request_timeout', 5 ), 160 160 /** 161 161 * Filters the number of redirects allowed during an HTTP request. … … 165 165 * @param int $redirect_count Number of redirects allowed. Default 5. 166 166 */ 167 'redirection' => apply_filters( 'http_request_redirection_count', 5 ),167 'redirection' => apply_filters( 'http_request_redirection_count', 5 ), 168 168 /** 169 169 * Filters the version of the HTTP protocol used in a request. … … 174 174 * Default '1.0'. 175 175 */ 176 'httpversion' => apply_filters( 'http_request_version', '1.0' ),176 'httpversion' => apply_filters( 'http_request_version', '1.0' ), 177 177 /** 178 178 * Filters the user agent value sent with an HTTP request. … … 182 182 * @param string $user_agent WordPress user agent string. 183 183 */ 184 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ),184 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ), 185 185 /** 186 186 * Filters whether to pass URLs through wp_http_validate_url() in an HTTP request. … … 191 191 * Default false. 192 192 */ 193 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),194 'blocking' => true,195 'headers' => array(),196 'cookies' => array(),197 'body' => null,198 'compress' => false,199 'decompress' => true,200 'sslverify' => true,201 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',202 'stream' => false,203 'filename' => null,193 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ), 194 'blocking' => true, 195 'headers' => array(), 196 'cookies' => array(), 197 'body' => null, 198 'compress' => false, 199 'decompress' => true, 200 'sslverify' => true, 201 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', 202 'stream' => false, 203 'filename' => null, 204 204 'limit_response_size' => null, 205 205 ); … … 209 209 210 210 // By default, Head requests do not cause redirections. 211 if ( isset( $args['method']) && 'HEAD' == $args['method'] )211 if ( isset( $args['method'] ) && 'HEAD' == $args['method'] ) { 212 212 $defaults['redirection'] = 0; 213 } 213 214 214 215 $r = wp_parse_args( $args, $defaults ); … … 224 225 225 226 // The transports decrement this, store a copy of the original value for loop purposes. 226 if ( ! isset( $r['_redirection'] ) ) 227 if ( ! isset( $r['_redirection'] ) ) { 227 228 $r['_redirection'] = $r['redirection']; 229 } 228 230 229 231 /** … … 247 249 $pre = apply_filters( 'pre_http_request', false, $r, $url ); 248 250 249 if ( false !== $pre ) 251 if ( false !== $pre ) { 250 252 return $pre; 253 } 251 254 252 255 if ( function_exists( 'wp_kses_bad_protocol' ) ) { … … 262 265 263 266 if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { 264 return new WP_Error( 'http_request_failed', __('A valid URL was not provided.'));267 return new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); 265 268 } 266 269 … … 290 293 if ( ! is_array( $r['headers'] ) ) { 291 294 $processedHeaders = WP_Http::processHeaders( $r['headers'] ); 292 $r['headers'] = $processedHeaders['headers'];295 $r['headers'] = $processedHeaders['headers']; 293 296 } 294 297 295 298 // Setup arguments 296 299 $headers = $r['headers']; 297 $data = $r['body'];298 $type = $r['method'];300 $data = $r['body']; 301 $type = $r['method']; 299 302 $options = array( 300 'timeout' => $r['timeout'],303 'timeout' => $r['timeout'], 301 304 'useragent' => $r['user-agent'], 302 'blocking' => $r['blocking'],303 'hooks' => new WP_HTTP_Requests_Hooks( $url, $r ),305 'blocking' => $r['blocking'], 306 'hooks' => new WP_HTTP_Requests_Hooks( $url, $r ), 304 307 ); 305 308 … … 333 336 // SSL certificate handling 334 337 if ( ! $r['sslverify'] ) { 335 $options['verify'] = false;338 $options['verify'] = false; 336 339 $options['verifyname'] = false; 337 340 } else { … … 360 363 if ( $proxy->use_authentication() ) { 361 364 $options['proxy']->use_authentication = true; 362 $options['proxy']->user = $proxy->username();363 $options['proxy']->pass = $proxy->password();365 $options['proxy']->user = $proxy->username(); 366 $options['proxy']->pass = $proxy->password(); 364 367 } 365 368 } … … 373 376 // Convert the response into an array 374 377 $http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] ); 375 $response = $http_response->to_array();378 $response = $http_response->to_array(); 376 379 377 380 // Add the original object to the array. 378 381 $response['http_response'] = $http_response; 379 } 380 catch ( Requests_Exception $e ) { 382 } catch ( Requests_Exception $e ) { 381 383 $response = new WP_Error( 'http_request_failed', $e->getMessage() ); 382 384 } … … 402 404 if ( ! $r['blocking'] ) { 403 405 return array( 404 'headers' => array(),405 'body' => '',406 'response' => array(407 'code' => false,406 'headers' => array(), 407 'body' => '', 408 'response' => array( 409 'code' => false, 408 410 'message' => false, 409 411 ), 410 'cookies' => array(),412 'cookies' => array(), 411 413 'http_response' => null, 412 414 ); … … 481 483 public static function validate_redirects( $location ) { 482 484 if ( ! wp_http_validate_url( $location ) ) { 483 throw new Requests_Exception( __( 'A valid URL was not provided.'), 'wp_http.redirect_failed_validation' );485 throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' ); 484 486 } 485 487 } … … 518 520 519 521 // Check to see if this transport is a possibility, calls the transport statically. 520 if ( ! call_user_func( array( $class, 'test' ), $args, $url ) )522 if ( ! call_user_func( array( $class, 'test' ), $args, $url ) ) { 521 523 continue; 524 } 522 525 523 526 return $class; … … 547 550 548 551 $class = $this->_get_first_available_transport( $args, $url ); 549 if ( ! $class )552 if ( ! $class ) { 550 553 return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); 554 } 551 555 552 556 // Transport claims to support request, instantiate it and give it a whirl. 553 if ( empty( $transports[$class] ) ) 554 $transports[$class] = new $class; 555 556 $response = $transports[$class]->request( $url, $args ); 557 if ( empty( $transports[ $class ] ) ) { 558 $transports[ $class ] = new $class; 559 } 560 561 $response = $transports[ $class ]->request( $url, $args ); 557 562 558 563 /** This action is documented in wp-includes/class-http.php */ 559 564 do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); 560 565 561 if ( is_wp_error( $response ) ) 566 if ( is_wp_error( $response ) ) { 562 567 return $response; 568 } 563 569 564 570 /** … … 585 591 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error 586 592 */ 587 public function post( $url, $args = array()) {588 $defaults = array( 'method' => 'POST');589 $r = wp_parse_args( $args, $defaults );590 return $this->request( $url, $r);593 public function post( $url, $args = array() ) { 594 $defaults = array( 'method' => 'POST' ); 595 $r = wp_parse_args( $args, $defaults ); 596 return $this->request( $url, $r ); 591 597 } 592 598 … … 602 608 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error 603 609 */ 604 public function get( $url, $args = array()) {605 $defaults = array( 'method' => 'GET');606 $r = wp_parse_args( $args, $defaults );607 return $this->request( $url, $r);610 public function get( $url, $args = array() ) { 611 $defaults = array( 'method' => 'GET' ); 612 $r = wp_parse_args( $args, $defaults ); 613 return $this->request( $url, $r ); 608 614 } 609 615 … … 619 625 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error 620 626 */ 621 public function head( $url, $args = array()) {622 $defaults = array( 'method' => 'HEAD');623 $r = wp_parse_args( $args, $defaults );624 return $this->request( $url, $r);627 public function head( $url, $args = array() ) { 628 $defaults = array( 'method' => 'HEAD' ); 629 $r = wp_parse_args( $args, $defaults ); 630 return $this->request( $url, $r ); 625 631 } 626 632 … … 634 640 * @return array Array with 'headers' and 'body' keys. 635 641 */ 636 public static function processResponse($strResponse) { 637 $res = explode("\r\n\r\n", $strResponse, 2); 638 639 return array('headers' => $res[0], 'body' => isset($res[1]) ? $res[1] : ''); 642 public static function processResponse( $strResponse ) { 643 $res = explode( "\r\n\r\n", $strResponse, 2 ); 644 645 return array( 646 'headers' => $res[0], 647 'body' => isset( $res[1] ) ? $res[1] : '', 648 ); 640 649 } 641 650 … … 652 661 * @param string $url The URL that was requested 653 662 * @return array Processed string headers. If duplicate headers are encountered, 654 * 663 * Then a numbered array is returned as the value of that header-key. 655 664 */ 656 665 public static function processHeaders( $headers, $url = '' ) { 657 666 // Split headers, one per array element. 658 if ( is_string( $headers) ) {667 if ( is_string( $headers ) ) { 659 668 // Tolerate line terminator: CRLF = LF (RFC 2616 19.3). 660 $headers = str_replace( "\r\n", "\n", $headers);669 $headers = str_replace( "\r\n", "\n", $headers ); 661 670 /* 662 671 * Unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) <US-ASCII SP, space (32)>, 663 672 * <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2). 664 673 */ 665 $headers = preg_replace( '/\n[ \t]/', ' ', $headers);674 $headers = preg_replace( '/\n[ \t]/', ' ', $headers ); 666 675 // Create the headers array. 667 $headers = explode("\n", $headers); 668 } 669 670 $response = array('code' => 0, 'message' => ''); 676 $headers = explode( "\n", $headers ); 677 } 678 679 $response = array( 680 'code' => 0, 681 'message' => '', 682 ); 671 683 672 684 /* … … 674 686 * In this case, determine the final HTTP header and parse from there. 675 687 */ 676 for ( $i = count( $headers)-1; $i >= 0; $i-- ) {677 if ( ! empty($headers[$i]) && false === strpos($headers[$i], ':') ) {678 $headers = array_splice( $headers, $i);688 for ( $i = count( $headers ) - 1; $i >= 0; $i-- ) { 689 if ( ! empty( $headers[ $i ] ) && false === strpos( $headers[ $i ], ':' ) ) { 690 $headers = array_splice( $headers, $i ); 679 691 break; 680 692 } 681 693 } 682 694 683 $cookies = array();695 $cookies = array(); 684 696 $newheaders = array(); 685 697 foreach ( (array) $headers as $tempheader ) { 686 if ( empty( $tempheader) )698 if ( empty( $tempheader ) ) { 687 699 continue; 688 689 if ( false === strpos($tempheader, ':') ) { 690 $stack = explode(' ', $tempheader, 3); 700 } 701 702 if ( false === strpos( $tempheader, ':' ) ) { 703 $stack = explode( ' ', $tempheader, 3 ); 691 704 $stack[] = ''; 692 705 list( , $response['code'], $response['message']) = $stack; … … 694 707 } 695 708 696 list($key, $value) = explode( ':', $tempheader, 2);697 698 $key = strtolower( $key );709 list($key, $value) = explode( ':', $tempheader, 2 ); 710 711 $key = strtolower( $key ); 699 712 $value = trim( $value ); 700 713 701 714 if ( isset( $newheaders[ $key ] ) ) { 702 if ( ! is_array( $newheaders[ $key ] ) ) 703 $newheaders[$key] = array( $newheaders[ $key ] ); 715 if ( ! is_array( $newheaders[ $key ] ) ) { 716 $newheaders[ $key ] = array( $newheaders[ $key ] ); 717 } 704 718 $newheaders[ $key ][] = $value; 705 719 } else { 706 720 $newheaders[ $key ] = $value; 707 721 } 708 if ( 'set-cookie' == $key ) 722 if ( 'set-cookie' == $key ) { 709 723 $cookies[] = new WP_Http_Cookie( $value, $url ); 724 } 710 725 } 711 726 … … 713 728 $response['code'] = intval( $response['code'] ); 714 729 715 return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies); 730 return array( 731 'response' => $response, 732 'headers' => $newheaders, 733 'cookies' => $cookies, 734 ); 716 735 } 717 736 … … 729 748 */ 730 749 public static function buildCookieHeader( &$r ) { 731 if ( ! empty( $r['cookies']) ) {750 if ( ! empty( $r['cookies'] ) ) { 732 751 // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. 733 752 foreach ( $r['cookies'] as $name => $value ) { 734 if ( ! is_object( $value ) ) 735 $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); 753 if ( ! is_object( $value ) ) { 754 $r['cookies'][ $name ] = new WP_Http_Cookie( 755 array( 756 'name' => $name, 757 'value' => $value, 758 ) 759 ); 760 } 736 761 } 737 762 … … 741 766 } 742 767 743 $cookies_header = substr( $cookies_header, 0, -2 );768 $cookies_header = substr( $cookies_header, 0, -2 ); 744 769 $r['headers']['cookie'] = $cookies_header; 745 770 } … … 761 786 public static function chunkTransferDecode( $body ) { 762 787 // The body is not chunked encoded or is malformed. 763 if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) 788 if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) { 764 789 return $body; 790 } 765 791 766 792 $parsed_body = ''; … … 771 797 while ( true ) { 772 798 $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); 773 if ( ! $has_chunk || empty( $match[1] ) ) 799 if ( ! $has_chunk || empty( $match[1] ) ) { 774 800 return $body_original; 775 776 $length = hexdec( $match[1] ); 801 } 802 803 $length = hexdec( $match[1] ); 777 804 $chunk_length = strlen( $match[0] ); 778 805 … … 784 811 785 812 // End of the document. 786 if ( '0' === trim( $body ) ) 813 if ( '0' === trim( $body ) ) { 787 814 return $parsed_body; 815 } 788 816 } 789 817 } … … 811 839 * @return bool True to block, false to allow. 812 840 */ 813 public function block_request( $uri) {841 public function block_request( $uri ) { 814 842 // We don't need to block requests, because nothing is blocked. 815 if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) 843 if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) { 816 844 return false; 817 818 $check = parse_url($uri); 819 if ( ! $check ) 845 } 846 847 $check = parse_url( $uri ); 848 if ( ! $check ) { 820 849 return true; 821 822 $home = parse_url( get_option('siteurl') ); 850 } 851 852 $home = parse_url( get_option( 'siteurl' ) ); 823 853 824 854 // Don't block requests back to ourselves by default. … … 835 865 } 836 866 837 if ( ! defined('WP_ACCESSIBLE_HOSTS') )867 if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) ) { 838 868 return true; 869 } 839 870 840 871 static $accessible_hosts = null; 841 static $wildcard_regex = array();872 static $wildcard_regex = array(); 842 873 if ( null === $accessible_hosts ) { 843 $accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS);844 845 if ( false !== strpos( WP_ACCESSIBLE_HOSTS, '*') ) {874 $accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS ); 875 876 if ( false !== strpos( WP_ACCESSIBLE_HOSTS, '*' ) ) { 846 877 $wildcard_regex = array(); 847 foreach ( $accessible_hosts as $host ) 878 foreach ( $accessible_hosts as $host ) { 848 879 $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); 849 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; 850 } 851 } 852 853 if ( !empty($wildcard_regex) ) 854 return !preg_match($wildcard_regex, $check['host']); 855 else 856 return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. 880 } 881 $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i'; 882 } 883 } 884 885 if ( ! empty( $wildcard_regex ) ) { 886 return ! preg_match( $wildcard_regex, $check['host'] ); 887 } else { 888 return ! in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. 889 } 857 890 858 891 } … … 887 920 */ 888 921 public static function make_absolute_url( $maybe_relative_path, $url ) { 889 if ( empty( $url ) ) 922 if ( empty( $url ) ) { 890 923 return $maybe_relative_path; 924 } 891 925 892 926 if ( ! $url_parts = wp_parse_url( $url ) ) { … … 908 942 if ( isset( $relative_url_parts['host'] ) ) { 909 943 $absolute_path .= $relative_url_parts['host']; 910 if ( isset( $relative_url_parts['port'] ) ) 944 if ( isset( $relative_url_parts['port'] ) ) { 911 945 $absolute_path .= ':' . $relative_url_parts['port']; 946 } 912 947 } else { 913 948 $absolute_path .= $url_parts['host']; 914 if ( isset( $url_parts['port'] ) ) 949 if ( isset( $url_parts['port'] ) ) { 915 950 $absolute_path .= ':' . $url_parts['port']; 951 } 916 952 } 917 953 … … 923 959 $path = $relative_url_parts['path']; 924 960 925 // Else it's a relative path.961 // Else it's a relative path. 926 962 } elseif ( ! empty( $relative_url_parts['path'] ) ) { 927 963 // Strip off any file components from the absolute path. … … 941 977 942 978 // Add the Query string. 943 if ( ! empty( $relative_url_parts['query'] ) ) 979 if ( ! empty( $relative_url_parts['query'] ) ) { 944 980 $path .= '?' . $relative_url_parts['query']; 981 } 945 982 946 983 return $absolute_path . '/' . ltrim( $path, '/' ); … … 960 997 public static function handle_redirects( $url, $args, $response ) { 961 998 // If no redirects are present, or, redirects were not requested, perform no action. 962 if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) 999 if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) { 963 1000 return false; 1001 } 964 1002 965 1003 // Only perform redirections on redirection http codes. 966 if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) 1004 if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) { 967 1005 return false; 1006 } 968 1007 969 1008 // Don't redirect if we've run out of redirects. 970 if ( $args['redirection']-- <= 0 ) 971 return new WP_Error( 'http_request_failed', __('Too many redirects.') ); 1009 if ( $args['redirection']-- <= 0 ) { 1010 return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); 1011 } 972 1012 973 1013 $redirect_location = $response['headers']['location']; 974 1014 975 1015 // If there were multiple Location headers, use the last header specified. 976 if ( is_array( $redirect_location ) ) 1016 if ( is_array( $redirect_location ) ) { 977 1017 $redirect_location = array_pop( $redirect_location ); 1018 } 978 1019 979 1020 $redirect_location = WP_Http::make_absolute_url( $redirect_location, $url ); … … 981 1022 // POST requests should not POST to a redirected location. 982 1023 if ( 'POST' == $args['method'] ) { 983 if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) 1024 if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) { 984 1025 $args['method'] = 'GET'; 1026 } 985 1027 } 986 1028 … … 988 1030 if ( ! empty( $response['cookies'] ) ) { 989 1031 foreach ( $response['cookies'] as $cookie ) { 990 if ( $cookie->test( $redirect_location ) ) 1032 if ( $cookie->test( $redirect_location ) ) { 991 1033 $args['cookies'][] = $cookie; 1034 } 992 1035 } 993 1036 } … … 1013 1056 */ 1014 1057 public static function is_ip_address( $maybe_ip ) { 1015 if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) 1058 if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) { 1016 1059 return 4; 1017 1018 if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) 1060 } 1061 1062 if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) { 1019 1063 return 6; 1064 } 1020 1065 1021 1066 return false;
Note: See TracChangeset
for help on using the changeset viewer.