Code BLACKGO: cookie banner free for a year. Create an account →

Publications / Guides

Cookie banner on a PHP website without a CMS – installation with one line of code

A website in plain PHP or your own system: how to add a cookie banner that blocks scripts on the server. One folder, one line of code, a footer link and a checklist.

Author: Robert.S Published: Updated: 3 min read

Cookie banner on a PHP website without a CMS – installation with one line of code

A website written in PHP without a CMS (or with your own system) also needs a banner that really blocks scripts until consent. You install consetgo by hand: one folder and one line of code. The module takes over the page on the server, blocks analytics, pixels, maps and videos, and unblocks them after the visitor gives consent.

Requirements

PHP 7.2 or newer and access to the site files (FTP or the file manager in the hosting panel). The module does not work in website builders without server access (Wix, Shopify, Squarespace and similar).

Installation step by step

  1. Download the file consent-x.y.z.zip from your consetgo account and upload the consent folder to the site root.
  2. Open the site’s start file (usually index.php) and on the second line, right below <?php, paste:
    require_once __DIR__ . '/consent/bootstrap.php';
  3. If the site has other PHP files opened directly (e.g. contact.php), add this line to them as well.
  4. Open the consent panel at your-site/consent/panel.php.
  5. Optionally add a link in the footer for changing consent:
    <a href="#" data-consent-open>Cookie settings</a>
    The banner also has a settings icon in the corner of the page.

Full instructions: consetgo for a PHP website.

Why the line has to be at the start

The module captures the page code before it reaches the browser – only then can it replace the scripts of services that need consent. If the page sends any HTML before the require_once line, that part goes to the browser unchanged.

Settings after installation

  1. In the Scanner tab enable scan mode and go through a few pages.
  2. In the Services and categories tab check the assignments. If the Google Analytics or GTM code is not on the site yet, you can enter the ID in the “Code” field – the module will insert the script itself: in advanced Consent Mode straight away, with “denied” signals, in basic mode after consent.
  3. In the Cookie policy tab copy the table into your privacy policy.

Cache

If the page is fully stored in an HTML cache and the server serves it without running PHP, blocking does not work – the module panel shows “limited mode”. Exclude such pages from the cache or use a cache that runs PHP.

Checklist

  • The require_once line on the second line of index.php and in every PHP file opened directly.
  • consent/panel.php opens; no “limited mode” message.
  • In a private window the banner shows on all pages.
  • Before a decision and after refusal: no _ga, _fbp cookies and no requests to analytics and advertising services.
  • The “Cookie settings” link in the footer opens the settings.

Step-by-step test: How to check whether a site sets cookies before consent. When the banner does not show: a list of common causes.

Questions and answers

Where exactly do I paste the line of code?

On the second line of the site’s start file (usually index.php), right below <?php – before any HTML code. The module has to take over the page before anything is sent to the browser.

I have several PHP files that are opened directly. What about them?

Add the same line to every file that opens directly in the browser (e.g. contact.php). Files included with include from index.php do not need it a second time.

Can this be done without changing files?

On Apache servers with PHP as a module you can add an auto_prepend_file directive in .htaccess pointing to the file consent/bootstrap.php. This does not work on every hosting – if the site stops working, remove that line and use require_once.

Read also

How should a proper cookie banner work?

How should a proper cookie banner work?

Guides

The banner should offer a real choice, and the website should carry it out: a refusal that is easy to find, separate purposes, scripts blocked after refusal and a permanent link for changing the decision. A short checklist using GA4, Meta Pixel and GTM as examples.

· 3 min read

How to choose a cookie consent management tool – 8 criteria

How to choose a cookie consent management tool – 8 criteria

Guides

Eight questions worth asking before you choose a cookie consent tool: blocking before consent, Consent Mode v2, consent log, languages, CMS integration, where the data is stored, price and support. Plus: free or paid module.

· 6 min read