Help us understand the problem. What is going on with this article?

PHPでドメインのSSL証明書の期限日を取得する

More than 1 year has passed since last update.

結構古めの記事しかなかったので自分のコピペ用にメモ

    /*
     * $domainからSSLの期限を取得
     */
    public static function getSSLDueDate($domain)
    {
        // 外部接続用のstream_contextを取得
        $stream_context = stream_context_create([
            'ssl' => [
                'capture_peer_cert'     => true
                // エラー回避用
                , 'verify_peer'         => false
                , 'verify_peer_name'    => false
            ]
        ]);
        // 外部接続
        $resource       = stream_socket_client(
            'ssl://' . $domain . ':443'
            , $err_no, $err_str, 5
            , STREAM_CLIENT_CONNECT, $stream_context
        );
        // ドメインの情報を取得
        $context        = stream_context_get_params($resource);
        $parsed         = openssl_x509_parse(
            $context['options']['ssl']['peer_certificate']
        );
        // SSL期限を返す
        return (strpos($parsed['subject']['CN'], $domain) !== false)
            ? date('Y-m-d', $parsed['validTo_time_t']) : null;
    }
hondy12345
渋谷で働いています。 メモ帳です。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした