PHP Installation

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

Important: The public key in your script must match a project in your Simple Commenter dashboard. If it doesn'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?id=sc_your_project_key"
        defer
    ></script>
</body>
</html>

Replace sc_your_project_key with your project's public key from the Simple Commenter dashboard.

Using a Config File

Store configuration separately:

<?php
// config.php
define('SIMPLE_COMMENTER_KEY', 'sc_your_project_key');
<?php
// header.php or footer.php
require_once 'config.php';
?>

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

Environment-Based Configuration

Use environment variables:

<?php
// config.php
$simpleCommenterKey = getenv('SIMPLE_COMMENTER_KEY') ?: '';
# .env or server config
SIMPLE_COMMENTER_KEY=sc_your_project_key

With vlucas/phpdotenv:

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

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

$simpleCommenterKey = $_ENV['SIMPLE_COMMENTER_KEY'] ?? '';

Include Pattern

Create a reusable include file:

<?php
// includes/simple-commenter.php
$key = defined('SIMPLE_COMMENTER_KEY')
    ? SIMPLE_COMMENTER_KEY
    : '';
?>
<script
    src="https://simplecommenter.com/js/comments.min.js?id=<?php echo htmlspecialchars($key); ?>"
    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?id=sc_your_project_key"
    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?id={{ config('services.simple_commenter.key') }}"
        defer
    ></script>
</body>
</html>
// config/services.php
return [
    'simple_commenter' => [
        'key' => env('SIMPLE_COMMENTER_KEY'),
    ],
];

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?id={{ simple_commenter_key }}"
        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 public key 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?