---
title: "Integration Guide on PHP"
description: "Integrating a PHP application with the Lacuna Scanner Service using the lacuna/scanner-client package: creating the ScannerClient and scan sessions."
canonical: "https://docs.lacunasoftware.com/en-us/articles/scanner/integration/php"
locale: "en"
product: "Scanner"
last_updated: "2026-10-12"
---

# Integration Guide on PHP

To integrate your PHP web application with the [Lacuna Scanner Service](https://docs.lacunasoftware.com/en-us/articles/scanner), follow the steps in this article.

> **Tip**
>
> Before you start, see the [integration overview](https://docs.lacunasoftware.com/en-us/articles/scanner/integration#overview).

First, add the [lacuna/scanner-client](https://packagist.org/packages/lacuna/scanner-client) package to your project.

With the **endpoint** and the **API Key** at hand, create a `ScannerClient`:

```php
$options = new ScannerOptions();
$options->endpoint = '...';
$options->apiKey = '...';
$scanner = new ScannerClient($options);
```

Call the `createScanSession($returnUrl)` method, passing the **returnUrl**, to start a session:

```php
$createResponse = $scanner->createScanSession("https://your-return-url/");
```

Use the value returned in the `redirectUrl` field to redirect the user on the frontend:

```js
location.href = '<?= $createResponse->redirectUrl ?>';
```

When you detect that the user has returned to your site (look for the `scanSessionId` argument in the URL), call the `getScanSession($scanSessionId)` method to get the scanned documents:

```php
$scanSession = $scanner->getScanSession($scanSessionId);
if ($scanSession->result == ScanSessionResults::SUCCESS) {
    $document = $scanSession->documents[0];
    
    $stream = $document->openRead();
    file_put_contents('...', $stream);
    $stream->close();
}
```

## Multifile sessions

You can let the user scan multiple documents. To do so, pass `true` as the second parameter, `multifile`, when creating the session:

```php
$response = $scanner->createScanSession("https://your-return-url/", true);
```

At the end of the process, instead of taking only the first document, iterate over the list of scanned documents:

```php
$scanSession = $scanner->getScanSession($scanSessionId);
if ($scanSession->result == ScanSessionResults::SUCCESS) {
	foreach ($scanSession->documents as $document) {
		// ...
	}
}
```
