1. Go to this page and download the library: Download stevecreekmore/cookies 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/ */
use Stevecreekmore\Cookies\Facades\Cookies;
// Check specific category
if (Cookies::hasConsent('analytics')) {
// Load analytics
}
// Get all consented categories
$categories = Cookies::getConsent();
// Returns: ['necessary', 'analytics']
// Check if any consent given
if (Cookies::hasGivenConsent()) {
// User has interacted with banner
}
// Check if all categories accepted
if (Cookies::hasAcceptedAll()) {
// User clicked "Accept All"
}
use Stevecreekmore\Cookies\Models\CookieConsentLog;
// Get consent history for a user
$history = CookieConsentLog::where('cookie_id', $consentId)
->latest()
->get();
// Each log contains:
// - cookie_id (unique user identifier)
// - consented_categories (JSON array)
// - ip_address
// - user_agent
// - action (accept_all, reject_all, custom, withdraw)
// - timestamp
'log_retention_days' => 1095, // 3 years (default)
use Stevecreekmore\Cookies\Models\CookieConsentLog;
// Manually clean up
CookieConsentLog::cleanupOldLogs();