PHP Installation

Add Simple Commenter to any PHP website by including the script in your templates.

Important: The domain in your script must exactly match the domain you registered in your Simple Commenter dashboard. If they don't match, the widget won't load.

Basic Installation

Add the script before the closing </body> tag:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My PHP Site</title>
</head>
<body>
    <?php include 'content.php'; ?>

    <!-- Add Simple Commenter before closing body -->
    <script
        src="https://simplecommenter.com/js/comments.min.js"
        data-domain="your-domain.com"
        defer
    ></script>
</body>
</html>

Replace your-domain.com with your actual domain from the Simple Commenter dashboard.

Dynamic Domain

Use the server's hostname:

<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>"
    defer
></script>

Using a Config File

Store configuration separately:

<?php
// config.php
define('SIMPLE_COMMENTER_DOMAIN', 'your-domain.com');
<?php
// header.php or footer.php
require_once 'config.php';
?>

<?php if (defined('SIMPLE_COMMENTER_DOMAIN') && SIMPLE_COMMENTER_DOMAIN): ?>
<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="<?php echo htmlspecialchars(SIMPLE_COMMENTER_DOMAIN); ?>"
    defer
></script>
<?php endif; ?>

Environment-Based Configuration

Use environment variables:

<?php
// config.php
$simpleCommenterDomain = getenv('SIMPLE_COMMENTER_DOMAIN') ?: '';
# .env or server config
SIMPLE_COMMENTER_DOMAIN=your-domain.com

With vlucas/phpdotenv:

<?php
require_once 'vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$simpleCommenterDomain = $_ENV['SIMPLE_COMMENTER_DOMAIN'] ?? '';

Include Pattern

Create a reusable include file:

<?php
// includes/simple-commenter.php
$domain = defined('SIMPLE_COMMENTER_DOMAIN')
    ? SIMPLE_COMMENTER_DOMAIN
    : $_SERVER['HTTP_HOST'];
?>
<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="<?php echo htmlspecialchars($domain); ?>"
    defer
></script>

Include in your pages:

<!-- Any page -->
<?php include 'includes/simple-commenter.php'; ?>
</body>
</html>

Conditional Loading

Only show on certain pages:

<?php
$show_widget = true;

// Don't show on admin pages
if (strpos($_SERVER['REQUEST_URI'], '/admin') === 0) {
    $show_widget = false;
}

// Don't show on login page
if ($_SERVER['REQUEST_URI'] === '/login.php') {
    $show_widget = false;
}
?>

<?php if ($show_widget): ?>
<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="your-domain.com"
    defer
></script>
<?php endif; ?>

Laravel

For Laravel applications, add to your blade layout:

<!-- resources/views/layouts/app.blade.php -->
<!DOCTYPE html>
<html>
<head>
    <title>@yield('title')</title>
</head>
<body>
    @yield('content')

    <script
        src="https://simplecommenter.com/js/comments.min.js"
        data-domain="{{ config('services.simple_commenter.domain') }}"
        defer
    ></script>
</body>
</html>
// config/services.php
return [
    'simple_commenter' => [
        'domain' => env('SIMPLE_COMMENTER_DOMAIN'),
    ],
];

Symfony

For Symfony applications, add to your twig base template:

{# templates/base.html.twig #}
<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}{% endblock %}</title>
</head>
<body>
    {% block body %}{% endblock %}

    <script
        src="https://simplecommenter.com/js/comments.min.js"
        data-domain="{{ simple_commenter_domain }}"
        defer
    ></script>
</body>
</html>

Verifying Installation

  1. Access your PHP site in a browser
  2. Look for the feedback widget button
  3. Check browser Developer Tools (F12) for errors
  4. View page source to confirm script is present

Troubleshooting

Widget not appearing

  • Verify the script is in the HTML output (view page source)
  • Check the domain matches your dashboard settings exactly
  • Look for PHP errors that might prevent output
  • Check browser console for JavaScript errors

Output buffering issues

If using output buffering, ensure the script is included before ob_end_flush():

<?php
ob_start();
// ... page content ...
include 'includes/simple-commenter.php';
ob_end_flush();

Security considerations

  • Always use htmlspecialchars() when outputting dynamic values
  • Store sensitive configuration outside the web root
  • Use HTTPS in production

Caching

If using PHP caching (OPcache, etc.), clear cache after changes:

  • Restart PHP-FPM: sudo service php-fpm restart
  • Or touch the file to invalidate: touch your-file.php

Need help? Contact support.

Was this page helpful?