Information & support > Knowledge base > Developer >Laatst bijgewerkt opMarch 12, 2021Server side usage – PHPIf your website is setting cookies server side, you can determine what type of cookies you are allowed to set by checking the users current consent state through standard cookie handling.PHPif (isset($_COOKIE["CookieConsent"])) { switch ($_COOKIE["CookieConsent"]) { case "0": //The user has not accepted cookies - set strictly necessary cookies only break; case "-1": //The user is not within a region that requires consent - all cookies are accepted break; default: //The user has accepted one or more type of cookies //Read current user consent in encoded JavaScript format $valid_php_json = preg_replace('/s*:s*([a-zA-Z0-9_]+?)([}[,])/', ':"$1"$2', preg_replace('/([{[,])s*([a-zA-Z0-9_]+?):/', '$1"$2":', str_replace("'", '"',stripslashes($_COOKIE["CookieConsent"])))); $CookieConsent = json_decode($valid_php_json); if (filter_var($CookieConsent->preferences, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts preference cookies } else { //Current user does NOT accept preference cookies } if (filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts statistics cookies } else { //Current user does NOT accept statistics cookies } if (filter_var($CookieConsent->marketing, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts marketing cookies } else { //Current user does NOT accept marketing cookies } } } else { //The user has not accepted cookies - set strictly necessary cookies only }14 day free trial CookiebotCookie scanner, cookie banner, cookie declaration and cookie consent in one solution.Use cookies on your website compliant with GDPR, ePrivacy and cookie legislationCookie management completely automatedCookie banner based on your corporate identityAutomatic composed cookie declaration, always up to dateStart 14 day free trialThe Cookiebot solution runs on 2,3 million websites, manages 7 billion monthly User Consents and supports 47+ languages.Previous Facebook Twitter LinkedIn E-mailNext
Laatst bijgewerkt opMarch 12, 2021Server side usage – PHPIf your website is setting cookies server side, you can determine what type of cookies you are allowed to set by checking the users current consent state through standard cookie handling.PHPif (isset($_COOKIE["CookieConsent"])) { switch ($_COOKIE["CookieConsent"]) { case "0": //The user has not accepted cookies - set strictly necessary cookies only break; case "-1": //The user is not within a region that requires consent - all cookies are accepted break; default: //The user has accepted one or more type of cookies //Read current user consent in encoded JavaScript format $valid_php_json = preg_replace('/s*:s*([a-zA-Z0-9_]+?)([}[,])/', ':"$1"$2', preg_replace('/([{[,])s*([a-zA-Z0-9_]+?):/', '$1"$2":', str_replace("'", '"',stripslashes($_COOKIE["CookieConsent"])))); $CookieConsent = json_decode($valid_php_json); if (filter_var($CookieConsent->preferences, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts preference cookies } else { //Current user does NOT accept preference cookies } if (filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts statistics cookies } else { //Current user does NOT accept statistics cookies } if (filter_var($CookieConsent->marketing, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts marketing cookies } else { //Current user does NOT accept marketing cookies } } } else { //The user has not accepted cookies - set strictly necessary cookies only }