Skip to content

Instantly share code, notes, and snippets.

@EdoardoVignati
Created May 1, 2017 18:32
Show Gist options
  • Save EdoardoVignati/4870b449cee1fbf8b3ddadad4e2de6b4 to your computer and use it in GitHub Desktop.
Save EdoardoVignati/4870b449cee1fbf8b3ddadad4e2de6b4 to your computer and use it in GitHub Desktop.
Simple cookie policy popup in php & js
<html>
<head>
<!--
Simple cookie info popup
Semplice popup di informativa per l'utilizzo dei cookies
Ti ringrazio se lasci qui questo commento.
Thanks for keeping here this comment.
To use this tool just insert the link to cookie policy ($cookiePolicy variable) and custom your css.
Then use <?php include("cookies_info_popup.php"); ?>
Per usare questo tool basta inserire il link alla cookie policy e modificare il css come preferisci.
Poi usa <?php include("cookies_info_popup.php"); ?> per importarlo
Created by Edoardo Vignati https://github.com/EdoardoVignati
-->
<style type=text/css>
#cookies{
margin-top:0px;
margin-left:0px;
background-color:#FF0103;
position:fixed;
width:100%;
// height:40px;
opacity:0.9;
z-index:999;
color:#FFFFFF;
padding-top:5px;
padding-bottom:10px;
text-align:center;
}
.cookieLinks{
color:#FFFFFF;
}
.cookieLinks:hover{
color:#000000;
}
</style>
<script type=text/javascript>
function hideCookie(){
/* Create the expiry date (today + 1 year) */
var CookieDate = new Date;
CookieDate.setFullYear(CookieDate.getFullYear( ) +1);
/* Set the cookie (acceptance of cookies usage) */
document.cookie = 'infoCookies=true; expires=' + CookieDate.toGMTString( ) + ';';
/* When "OK" clicked, hides this popup */
document.getElementById("cookies").style.display = "none";
}
</script>
</head>
<body>
<?php
/* Check if the user has not visited yet this website
(or not accepted the cookies usage) */
if(!isset($_COOKIE['infoCookies']))
{
/* Insert below the link to cookies policy */
$cookiePolicy = "http://LINK TO COOKIES POLICY";
echo " <div id='cookies'>This website uses cookies to improve your navigation and technical cookies";
echo " (<a class='cookieLinks' target='_blank' href='$cookiePolicy'>info</a>).";
echo " Browsing this site you accept the cookies usage.";
/* if "OK" clicked, call the JS function to hide the popup and set the cookie */
echo" <a onClick='hideCookie();' class='cookieLinks' href=#>OK</a></div>";
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment