Passed
Pull Request — master (#1)
by John
02:11
created

exampleHTTP.php (3 issues)

1
<?php
2
//Sets the maximum execution time to two minutes, to be sure.
3
ini_set('max_execution_time', 120);
4
// Including the LetsEncrypt Client.
5
require_once('LEClient/LEClient.php');
6
7
// Listing the contact information in case a new account has to be created.
8
$email = array('[email protected]');
9
// Defining the base name for this order
10
$basename = 'example.org';
11
// Listing the domains to be included on the certificate
12
$domains = array('example.org', 'test.example.org');
13
14
// Initiating the client instance. In this case using the staging server (argument 2) and outputting all status and debug information (argument 3).
15
$client = new LEClient($email, true, LECLient::LOG_STATUS);
16
// Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17
$order = $client->getOrCreateOrder($basename, $domains);
18
// Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
if(!$order->allAuthorizationsValid())
20
{
21
	// Get the HTTP challenges from the pending authorizations.
22
	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP);
0 ignored issues
show
LEOrder::CHALLENGE_TYPE_HTTP of type string is incompatible with the type integer expected by parameter $type of LEOrder::getPendingAuthorizations(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
	$pending = $order->getPendingAuthorizations(/** @scrutinizer ignore-type */ LEOrder::CHALLENGE_TYPE_HTTP);
Loading history...
23
	// Walk the list of pending authorization HTTP challenges.
24
	if(!empty($pending))
25
	{
26
		foreach($pending as $challenge)
27
		{
28
			// Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is set.
29
			$folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/';
30
			// Check if that directory yet exists. If not, create it.
31
			if(!file_exists($folder)) mkdir($folder, 0777, true);
32
			// Store the challenge file for this domain.
33
			file_put_contents($folder . $challenge['filename'], $challenge['content']);
34
			// Let LetsEncrypt verify this challenge.
35
			$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_HTTP);
0 ignored issues
show
LEOrder::CHALLENGE_TYPE_HTTP of type string is incompatible with the type integer expected by parameter $type of LEOrder::verifyPendingOrderAuthorization(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
			$order->verifyPendingOrderAuthorization($challenge['identifier'], /** @scrutinizer ignore-type */ LEOrder::CHALLENGE_TYPE_HTTP);
Loading history...
36
		}
37
	}
38
}
39
// Check once more whether all authorizations are valid before we can finalize the order.
40
if($order->allAuthorizationsValid())
41
{
42
	// Finalize the order first, if that is not yet done.
43
	if(!$order->isFinalized()) $order->finalizeOrder();
44
	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
45
	if($order->isFinalized()) $order->getCertificate();
46
}
47
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...