Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@hondy12345

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

More than 3 years have 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;
    }
0
Help us understand the problem. What is going on with this article?
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
hondy12345
渋谷で働いています。 メモ帳です。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?