PHP code example of spatie / ssl-certificate

1. Go to this page and download the library: Download spatie/ssl-certificate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / ssl-certificate example snippets


use Spatie\SslCertificate\SslCertificate;

// fetch the certificate using an url
$certificate = SslCertificate::createForHostName('spatie.be');

// or from a certificate file
$certificate = SslCertificate::createFromFile($pathToCertificateFile);

// or from a string
$certificate = SslCertificate::createFromString($certificateData);

$certificate->isValid(); // returns true if the certificate is currently valid

$certificate->expirationDate(); // returns a Carbon instance Carbon
$certificate->validFromDate(); // returns a Carbon instance Carbon

$certificate->daysUntilExpirationDate(); // returns the amount of days between today and expirationDate
$certificate->lifespanInDays(); // return the amount of days between validFromDate and expirationDate

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"
$certificate->getOrganization(); // returns the organization name when available
$certificate->getPublicKeyAlgorithm(); // returns the public key algorithm
$certificate->getPublicKeySize(); // returns the public key algorithm
$certificate->getSignatureAlgorithm(); // returns the signature algorithm

$certificate = SslCertificate::createForHostName('spatie.be');

$certificate = SslCertificate::createForHostName('spatie.be:443');

SslCertificate::download()
   ->usingPort($customPort)
   ->forHost($hostName);

SslCertificate::download()
   ->fromIpAddress($ipAddress)
   ->forHost($hostName);

SslCertificate::download()
    ->fromIpAddress('2a00:1450:4001:80e::200e')
    ->forHost('google.com');

SslCertificate::download()
   ->withSocketContextOptions([
      'option' => 'value',
   ])
   ->forHost($hostName);

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"

$certificate->getDomain(); // returns "spatie.be"

$certificate->getSignatureAlgorithm(); // returns "RSA-SHA256"

$certificate->getOrganization(); // returns "Spatie BVBA"

$certificate->getAdditionalDomains(); // returns ["spatie.be", "www.spatie.be]

$certificate->getFingerprint(); // returns a fingerprint for the certificate

$certificate->getFingerprintSha256(); // returns a SHA256 fingerprint for the certificate

$certificate->validFromDate(); // returns an instance of Carbon

$certificate->expirationDate(); // returns an instance of Carbon

$certificate->isValid(); // returns a boolean

$certificate->isValid('spatie.be'); // returns true;
$certificate->isValid('laravel.com'); // returns false;

$certificate->isValidUntil(Carbon::now()->addDays(7)); // returns a boolean

$certificate->isExpired(); // returns a boolean if expired

$certificateProperties = $certificate->toArray();

\Spatie\SslCertificate\SslCertificate::createFromArray($certificateProperties);