PHP code example of jyxon / gdpr-cookie-compliance

1. Go to this page and download the library: Download jyxon/gdpr-cookie-compliance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jyxon / gdpr-cookie-compliance example snippets


use Jyxon\GdprCookieCompliance\Cookie\Settings;

//This will default to the config.json provided with the package.
$settings = new Settings();

$settings = new Settings('/some/path/on/my/server/config.json');

use Jyxon\GdprCookieCompliance\Cookie\Settings;
use Jyxon\GdprCookieCompliance\Cookie\Manager;

$settings = new Settings();
$manager = new Manager($settings);

//old
setcookie('functional_cookie_name', 'some-non-tracking-value', time() + 3600, '/', '*.mydomain', 1);
setcookie('tracking_cookie_name', 'uniquely-identifiable-information', time() + 360000, '/', '*.mydomain', 1);

//new
$manager->setCookie('functional', 'functional_cookie_name', 'some-non-tracking-value', time() + 3600, '/', '*.mydomain.com', 1);
$manager->setCookie('analytical', 'tracking_cookie_name', 'uniquely-identifiable-information', time() + 360000, '/', '*.mydomain.com', 1);

/**
 * Checks wether there is consent for setting a cookie.
 *
 * @param string $scope
 *
 * @return bool
 */
public function canSet(string $scope): bool;

/**
 * Send a cookie if there is consent. Also deletes cookies for which is no longer consent.
 *
 * @param string $scope
 * @param string $name
 * @param string $value
 * @param integer $expire
 * @param string $path
 * @param string $domain
 * @param boolean $secure
 * @param boolean $httponly
 *
 * @return bool
 */
public function setCookie(string $scope, string $name, string $value = "", int $expire = 0, string $path = "", string $domain = "", bool $secure = false, bool $httponly = false): bool;

/**
 * Fetch a cookie if there is consent. Also deletes cookies for which is no longer consent.
 *
 * @param  string  $scope
 * @param  string  $name
 * @param  string  $path
 * @param  string  $domain
 * @param  boolean $secure
 * @param  boolean $httponly
 *
 * @return mixed
 */
public function getCookie(string $scope, string $name, string $path = "", string $domain = "", bool $secure = false, bool $httponly = false);