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.

Latest posts
- Google merged the Google tag with Tag Manager – what it changes for cookie consent
- Advertising on Google or measuring traffic? Check whether you need a cookie banner
- How should a proper cookie banner work?
- How to prepare your website for consetgo – pre-installation checklist
- Cookies in an online shop – a practical checklist
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
- Download the file consent-x.y.z.zip from your consetgo account and upload the
consentfolder to the site root. - Open the site’s start file (usually
index.php) and on the second line, right below<?php, paste:require_once __DIR__ . '/consent/bootstrap.php'; - If the site has other PHP files opened directly (e.g.
contact.php), add this line to them as well. - Open the consent panel at
your-site/consent/panel.php. - Optionally add a link in the footer for changing consent:
The banner also has a settings icon in the corner of the page.
<a href="#" data-consent-open>Cookie settings</a>
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
- In the Scanner tab enable scan mode and go through a few pages.
- 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.
- 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_onceline on the second line of index.php and in every PHP file opened directly. consent/panel.phpopens; 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.