3v4l.org

run code in 300+ PHP versions simultaneously
<?php #ここでドメイン名を指定 $domain_name = 'yahoo.co.jp'; #外部接続するために必要なストリームコンテキストを取得する(ここでアロー演算子でSSL証明書の情報を絞り混んでます) $stream_context = stream_context_create(array( 'ssl' => array('capture_peer_cert' => true) )); #stream_socket_client関数で外物接続。$errno は接続失敗時のシステムエラーのレベルが #$errstrは接続失敗した時のエラーメッセージが入ります 5 と書いてあるところはタイムアウトまでの時間です $resource = stream_socket_client( 'ssl://' . $domain_name . ':443',$errno,$errstr,5,STREAM_CLIENT_CONNECT,$stream_context ); #帰ってきた情報からstream_context_get_paramsで選んだドメインの情報を配列で取得します $cont = stream_context_get_params($resource); #上記で撮ってきた配列から配列からpeer_certificateという場所から idを取得してそれから全情報を取得する。 $parsed = openssl_x509_parse($cont['options']['ssl']['peer_certificate']); #あとは全情報から配列を抜き出して絞り込んで好きな形式に期限を出す if(strpos($parsed['subject']['CN'], $domain_name) !== false){ echo date('Y/m/d', $parsed['validTo_time_t']); }else{ echo 'not contract.'; }
Output for 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Warning: stream_socket_client(): Unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 10 Fatal error: Uncaught TypeError: stream_context_get_params(): Argument #1 ($context) must be of type resource, false given in /in/9au6Z:14 Stack trace: #0 /in/9au6Z(14): stream_context_get_params(false) #1 {main} thrown in /in/9au6Z on line 14
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.2.0 - 8.2.29
Warning: stream_socket_client(): Unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 10 Fatal error: Uncaught TypeError: stream_context_get_params(): Argument #1 ($context) must be of type resource, bool given in /in/9au6Z:14 Stack trace: #0 /in/9au6Z(14): stream_context_get_params(false) #1 {main} thrown in /in/9au6Z on line 14
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
Warning: stream_socket_client(): Unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 11 Fatal error: Uncaught TypeError: stream_context_get_params(): Argument #1 ($context) must be of type resource, bool given in /in/9au6Z:14 Stack trace: #0 /in/9au6Z(14): stream_context_get_params(false) #1 {main} thrown in /in/9au6Z on line 14
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: stream_socket_client(): unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 11 Warning: stream_context_get_params() expects parameter 1 to be resource, bool given in /in/9au6Z on line 14 Fatal error: Uncaught Error: Call to undefined function openssl_x509_parse() in /in/9au6Z:16 Stack trace: #0 {main} thrown in /in/9au6Z on line 16
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
Warning: stream_socket_client(): unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 11 Warning: stream_context_get_params() expects parameter 1 to be resource, boolean given in /in/9au6Z on line 14 Fatal error: Uncaught Error: Call to undefined function openssl_x509_parse() in /in/9au6Z:16 Stack trace: #0 {main} thrown in /in/9au6Z on line 16
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Warning: stream_socket_client(): unable to connect to ssl://yahoo.co.jp:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /in/9au6Z on line 12 Warning: stream_context_get_params() expects parameter 1 to be resource, boolean given in /in/9au6Z on line 14 Fatal error: Call to undefined function openssl_x509_parse() in /in/9au6Z on line 16
Process exited with code 255.

preferences:
191.56 ms | 416 KiB | 5 Q