# Add protected playback to your PHP website Connect your own sign-in and course access to the web player and the enrolled DRM-X player app. A student signs in to your website and chooses a lesson. This guide connects the two buttons on that lesson to your course access records. One plays in the browser. The other opens the enrolled DRM-X player app. ## 1. Try the two buttons[#](#try) Sign in to the [live PHP sample](https://developer.drm-x.com/php-sample/?lang=en). Beside **WayMaker**, select the web playback icon and watch the timeline advance. Select the app icon on the same row to open WayMaker in the installed app. On first use, your browser may ask permission to open the app. ![WayMaker player and playlist controls](https://docs.drm-x.com/assets/php-player/php-playlist-en.png)The two icons on the WayMaker row let the student choose where to watch. ## 2. Play your own video[#](#setup) Extract the [complete PHP sample](https://developer.drm-x.com/downloads/drmx-php-sample-20261204.18.zip). Install PHP 8.2 or later with cURL. In DRM-X Console, publish one protected title and create a playback API client in the same environment. If you host the media, register its encrypted DASH or HLS address. In `config/drmx.php`, replace the corresponding entries shown below. Set the three environment variables on the PHP server. Use the Content ID of your published lesson and a license policy enabled for your environment. ``` 'siteId' => getenv('DRMX_SITE_ID') ?: '', 'siteKey' => getenv('DRMX_SITE_KEY') ?: '', 'accessKey' => getenv('DRMX_ACCESS_KEY') ?: '', 'content' => ['id' => 'course-101-lesson-1', 'title' => 'Lesson 1', 'type' => 'vod'], 'licensePolicyTemplate' => 'multi-tier-standard', ``` From the extracted folder, run `.\run-local.ps1` on Windows or `bash run-local.sh` on macOS or Linux. Open `http://127.0.0.1:8086/`. On your production server, use HTTPS, set the document root to `public/` and route requests as shown in `router.php`. ## 3. Connect your login and lesson page[#](#access) Connect `authenticated_user_id()` in `src/bootstrap.php` to your existing login. Turn off demo login on your production site. Supply `authorizeContent` in `config/drmx.php`. This example assumes an existing PDO connection and a table containing one active entitlement per viewer and lesson. Adapt the query to your schema. ``` 'authorizeContent' => static function (string $viewerId, string $contentId) use ($pdo): bool { $query = $pdo->prepare( 'SELECT 1 FROM course_access WHERE viewer_id = ? AND content_id = ? AND active = 1' ); $query->execute([$viewerId, $contentId]); return (bool) $query->fetchColumn(); }, ``` Use the shipped page to offer a playlist with both buttons. To embed only the web player on an existing lesson page, retain the Shaka runtime setup from `public/index.php` and add this element. These paths assume the sample is mounted at `/php-sample/`. ``` ``` The player calls the website session endpoint when a viewer selects a title. This is a minimal streaming request for a browser that supports Widevine. The SDK selects the supported DRM system for the actual browser. A successful response provides the registered media manifest and license configuration. In token-proxy mode PHP keeps the DRM License Token server-side. ``` POST /php-sample/api/drmx/playback-session Content-Type: application/json {"contentId":"course-101-lesson-1","contentType":"vod","drmSystem":"widevine","playbackMode":"streaming"} ``` ## 4. Enable app playback for your domain[#](#app) The public demo already has a registered publisher. Register your own publisher application IDs, HTTPS redemption endpoint and permitted Content IDs with DRM-X. Confirm support for your domain’s first-use enrollment path with the distributed app. The demo’s automatic Apple first-use flow is specific to the demo host. For an app you distribute yourself, use the DRM-X player SDK and your registered application identity. Follow `NATIVE-PILOT.md` in the ZIP. Configure the private `nativePilot` array, its `authorize` callback and the supported installation pairing method. Enable `useWebTitle` and `useWebPlaylist` to use the same catalog for both buttons. Each click requests a new launch code. The app proves its enrolled installation when redeeming the code. Share the lesson page URL with students. When you adapt the playlist, keep the click handler in `public/index.php`. It sends the following fields to `POST /php-sample/api/drmx/native-pilot`. This excerpt shows the data the shipped handler assembles. Its platform-specific steps obtain installation proof and deliver the returned launch code to the app. ``` const response = await fetch(panel.dataset.endpoint, { method: 'POST', credentials: 'same-origin', cache: 'no-store', signal, headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ action, platform, csrf: panel.dataset.csrf, intent: intents[contentId], contentId, ...fields }) }); ``` The sample issues `csrf` for the signed-in session and an `intent` for the selected title. Reuse the page’s per-click logic so a retry receives a fresh code. The `browser` hint helps route the handoff. `originalTab` requests confirmation in the originating Mac tab. PHP rechecks entitlement independently of these browser hints. ![Browser sign-in, website authorization and enrolled player handoff](https://docs.drm-x.com/assets/php-player/php-player-handoff-en.svg)The website authorizes the student. The native path also verifies the installation. **Require DRM-X player app or native SDK** is off by default. Leave it off to offer both playback options. Turn it on to require an enrolled native player for license acquisition and renewal. For a native-only course, show the app button as the available option. ## Parameter reference[#](#parameters) | Name | Meaning | | --- | --- | | siteId | Environment UUID owning the published title and playback client. | | siteKey / accessKey | Server-side client ID and secret. Grant the client license-tokens:create. | | content.id / content.type | Published Content ID and vod or live. | | session-endpoint | Same-origin POST endpoint. The player supplies contentId, drmSystem and capabilities. PHP reads the viewer identity from the session. | | nativePilot.applicationIds | Registered publisher application IDs for windows, apple and android. Configure permitted titles on the publisher. | | appAuthenticate | For an SDK-based app, validate its viewer token and return the same user ID used by website login. | ## Verify your integration[#](#check) Play the same lesson with each button. Confirm the browser timeline advances and the app opens the selected title. Sign out and click again. Your site should request sign-in before issuing a session or launch code. A student without course access should receive 403. Copying a launch code to another installation should fail redemption. If a code expires, return to the lesson and select the app button again. [Playback session API reference](https://docs.drm-x.com/api-reference/playback-sessions) · [Web SDK](https://docs.drm-x.com/sdk/web) · [Android SDK](https://docs.drm-x.com/sdk/android) · [Apple SDK](https://docs.drm-x.com/sdk/apple)