# Free Live Chat for a PHP Website: Copy-Paste Setup (Plain PHP and Laravel)

To add free live chat to a PHP website, paste a hosted chat widget's one-line script into the footer file every page includes (such as `footer.php` or your Laravel layout), verify the domain, and send a test message. If your site has accounts, sign each user's ID on the server with `hash_hmac` so the chat knows who's writing and nobody can pretend to be them. This guide does it with SealReply, a hosted live chat with a free plan that never expires.

## Why a hosted widget for a PHP site

PHP chat scripts you self-host usually mean polling or a separate WebSocket server, an admin panel to secure, and no phone notifications. A hosted widget keeps your PHP code untouched: the chat runs from the vendor's CDN, and you answer from a browser dashboard or a phone app.

What to look for in a free plan, and how [SealReply](https://www.sealreply.com/?ref=hashnode) compares:

| Need | Why it matters | SealReply Free |
| --- | --- | --- |
| No expiry | A 14-day trial isn't a free plan | Free for as long as you like, no card |
| Volume | Enough for a small site | 1 agent, 1 website, 300 chats a month, 30 days of history |
| After hours | Visitors still reach you | Business hours, offline form, replies by email |
| Alerts | You hear about chats away from the desk | Push notifications, iPhone app |
| Page weight | Don't slow down your site | About 38 KB, loaded async |
| Logged-in users | Know who you're talking to | HMAC-signed identity, on every plan |

## Step 1: Get your embed code

Sign up, add your website's address (the widget only loads on that domain and its subdomains), and copy the code:

```html
<script src="https://cdn.sealreply.com/widget.js" data-site-key="sk_…" async></script>
```

## Step 2: Paste it into your shared footer

Most PHP sites already have one file every page includes. Put the script just before `</body>` there, once.

**Plain PHP:**

```php
<?php // includes/footer.php ?>
  <footer>…</footer>
  <script src="https://cdn.sealreply.com/widget.js" data-site-key="sk_…" async></script>
</body>
</html>
```

**Laravel (Blade):** in the main layout, for example `resources/views/layouts/app.blade.php`. Keeping the key in config makes it easy to change per environment:

```blade
    @yield('content')
    <script src="https://cdn.sealreply.com/widget.js"
            data-site-key="{{ config('services.sealreply.site_key') }}" async></script>
</body>
</html>
```

```php
// config/services.php
'sealreply' => [
    'site_key' => env('SEALREPLY_SITE_KEY'),
],
```

The site key isn't secret; it appears in every page's HTML anyway.

## Step 3: Verify the domain and test

Open your site once and the domain usually verifies itself, because the code is found on your home page. If a login wall or maintenance page is in the way, add the DNS TXT record or upload the small file the dashboard gives you.

Then open the site in a private window, send a message from the chat button, and reply from the dashboard.

## Step 4: Identify logged-in users with hash_hmac

If your PHP app has accounts, you'll want agents to see *which* customer is writing. Printing a plain user ID into the page isn't enough: anyone can edit it in DevTools and chat as someone else. Instead:

1. In the site settings, turn on **Visitor identity verification** and copy the secret (it starts with `ids_` and is shown once). Store it as an environment variable, never in the repo.
2. Sign the user's ID on the server.
3. Print the ID and signature before `widget.js` loads.

```php
<?php
// before the widget script, only when a user is signed in
if ($user) {
    $identity = [
        'external_id'   => (string) $user->id,
        'identity_hash' => hash_hmac('sha256', (string) $user->id, getenv('SEALREPLY_IDENTITY_SECRET')),
        'name'          => $user->name,
        'email'         => $user->email,
    ];
    echo '<script>window.sealreplySettings = { identity: '
        . json_encode($identity, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)
        . ' };</script>';
}
?>
<script src="https://cdn.sealreply.com/widget.js" data-site-key="sk_…" async></script>
```

A few rules that save debugging time:

- **Sign an ID that never changes**, like the primary key, not the email. Change the email and a signature over it becomes a different person.
- **Sign and send the exact same string.** `"42"` and `" 42"` are different users.
- **Never compute the hash in JavaScript.** The secret would be in the browser for anyone to read.
- A missing or wrong signature doesn't break the chat; the visitor just stays anonymous. So after you ship, sign in with a real account and check the dashboard shows the visitor as **Verified**.

Using `json_encode` with the `JSON_HEX_*` flags keeps a name like `</script>` from breaking out of the script tag.

## The chat doesn't show up

- **Cache.** A page cache or CDN is serving the old HTML. Clear it.
- **Wrong address.** You opened `www.` but added the domain without it, or the other way round. Add every address visitors use.
- **Not verified yet.** Open the home page once, or use the DNS record.
- **Pasted twice.** Two chat buttons means two script tags, usually one in a layout and one in a page template. Keep one.

## Summary

For a PHP or Laravel site, free live chat is one script in your shared footer, plus a `hash_hmac` call if you want verified users. [SealReply is free to use](https://www.sealreply.com/signup?ref=hashnode), with no card and no time limit. For the identity setup in more depth, including signed member details like plan and order count, see [Identify logged-in users in live chat](https://www.sealreply.com/blog/identify-logged-in-users-live-chat?ref=hashnode).

*Disclosure: the Gingertool team also works on SealReply. This post was written with AI assistance.*

