Documentation index

Cookie solution ›

Prior consent for cookies – PHP Class


This class allows you to scan a page in PHP and run the automatic blocking of scripts mentioned in this document. Download the class Here is an example of php class integration:
<?php
    function iubenda_system($html)
    {
        if(!function_exists("file_get_html")) {
            require_once("simple_html_dom.php");
        }

        require_once("iubenda.class.php");

        if(!Page::consent_given() && !Page::bot_detected())
        {
            $page = new Page($html);
            $page->parse();
            $html = $page->get_converted_page();
        }

        return $html;
    }
    
    ob_start("iubenda_system");
?>
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_POLICY_START--> e <!--IUB_COOKIE_POLICY_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: iubenda.com/en/help/posts/1229. We suggest you consult posts relating to the alteration of script, img and iframe tags As a last step the script invokes the get_converted_page() of the Page object and returns the page modifed in such a way that no cookie will be generated. The plugin is currently able to detect and automatically block the following scripts:
  • Facebook widgets
  • Twitter widgets
  • Google+ widgets
  • Google AdSense
  • YouTube widgets
  • AddThis widgets
  • ShareThis widgets
Download the iubenda.class.php Please note that at the moment the Cookie Solution is optimised 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.load.php"; after the first line;
  • still in the same location, add the files "iubenda.class.faster.php" and "iubenda.load.php" 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 Cookie Solution code.
Download the files to use the PHP class on CMS like Magento or Prestashop

PHP Class changelog

Expand the changelog

== Changelog ==

= 2.1 =

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

= 2.0 =

* New: 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
* New: Created a new option that allow users to enable/disable the parsing engine and to select the parsing engine between stable and experimental

= 1.0 =

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

-----


Still have questions?

Visit our support forum Email us