Iubenda logo
Start generating


Table of Contents

Blocking Cookies Prior to Consent with the PHP Class

The usage of the PHP class is only recommended for advanced users given that the procedure may require some customization depending on the site and the CMS utilized. Also, keep in mind that JavaScript is required to visualize the banner and cookie policy.

This class allows you to scan a page in PHP and run the automatic blocking of scripts mentioned in this document. You can access the class via direct download or Packagist.

Here is an example of the PHP class integration:

function iubenda_system( $html, $type = 'page' ) {
  if ( empty( $html ) )
  require_once( 'iubenda.class.php' );
  // separator
  if ( ! iubendaParser::consent_given() && ! iubendaParser::bot_detected() ) {
    $iubenda = new iubendaParser( $html, array( 'type' => in_array( $type, array( 'page', 'faster' ), true ) ? $type : 'page' ) );
    $html = $iubenda->parse();
  // finished
  return $html;

The iubenda_system method verifies if the page visitor consents to the use of cookies. If this is the case, the script returns the HTML provided as a parameter without taking any action such as parsing/replacing.

Simply copy your method into the PHP document and then call it with the following syntax iubenda_system("contenutohtml"); that will return the code.

  • Parsing/replacing the portions of code contained within <!--IUB-COOKIE-BLOCK-START--> and <!--IUB-COOKIE-BLOCK-END-->
  • Automatic parsing/replacing of iframe that contain defined src
  • Automatic parsing/replacing of scripts that contain defined src

These operations take place in accordance with the rules explained in this guide. We suggest that you consult the posts relating to the alteration of script, img and iframe tags.

  • AdRoll
  • AddThis widgets
  • Bing
  • CodePen
  • Criteo
  • Disqus
  • Elevio
  • Facebook Comments
  • Facebook widgets
  • Freshchat
  • Google AdSense
  • Google Analytics
  • Google Maps
  • Google ReCaptcha
  • Google Site Search
  • Google Tag Manager
  • Google oAuth
  • Google+ widgets
  • Headway
  • Instagram widgets
  • Kissmetrics
  • LinkedIn widgets
  • Mixpanel
  • Neodata
  • Olark
  • Optimizely
  • Outbrain
  • PayPal widgets
  • Pingdom
  • Pinterest widgets
  • Segment
  • ShareThis widgets
  • Twitter widgets
  • UserVoice
  • Vimeo
  • YouTube

Please note that at the moment the Privacy Controls and Cookie Solution is optimized to comply with very strict Italian implementation regulations (this can only improve compliance in other jurisdictions).

How to use the iubenda PHP class on a CMS like Magento or PrestaShop

To use the iubenda PHP class on Magento or PrestaShop you simply need to access the Magento/PrestaShop CMS file folder and follow the instructions below:

  • open the file index.php;
  • copy and paste require __DIR__ . "/iubenda.class.php"; after the first line;
  • still in the same location, add the simple_html_dom.php file which you can download here or using the button below;
  • finally, always at the same location, create a file called iubenda.cookies.js containing your Privacy Controls and Cookie Solution code.

Security Fix: limit url sanitize to http protocols


Fix: AddThis per-purpose category
New: Google AMP support from release v4.1.0


New: Per-purpose script blocking support
New: Reject button support


New: Introducing wildcard support for scripts and iframes


New: Introducing a way to skip specific script parsing


Tweak: Improved Youtube and Google Maps support


Tweak: Update composer.json autoloader


New: Option to block custom scripts and iframes
Tweak: Update and extend the list of blocked scripts including Google Site Search, Google oAuth, LinkedIn widgets, PayPal widgets, Pinterest, AddThis, Disqus, Optimizely, Neodata, Criteo, Outbrain, Headway, Codepen, Freshchat, UserVoice, AdRoll, Olark, Segment, Kissmetrics, Mixpanel, Pingdom, Bing and Elevio


Tweak: Update and unify iubenda parsing engine


Fixed a series of conflicts with UTF-8 special characters caused by the experimental parsing engine


Introduced a MUCH FASTER experimental parsing engine (visit the plugin options and select the experimental parsing engine) -> this one is called iubenda.class.faster.php and has a version number of 2.0.0, while the standard iubenda.class.php is still at 1.0.1

Created a new option that allow users to enable/disable the parsing engine and to select the parsing engine between stable and experimental


Introduction of the PHP Class. Now the plugin uses iubenda.class.php

See also