I am in need of a unique variable that is valid for a single day. This variable should be able to identify the individual website user and remain exclusive to that user. Once obtained, I intend to store this variable in a MySQL column. However, I am facing challenges in creating such a variable.
Additionally, I require a validation process to check if the record already exists in the table, preventing the creation of a new one within 24 hours.
To achieve this, my initial thought was to use a cookie that expires after one day (although I am not very familiar with cookies). Currently, I am having difficulty figuring out how to alert the cookie as shown below:
$(document).ready(function() {
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Inline Button in Table
var cookie_variable = $('#table').on('click', 'a.cookie_button', function () {
alert(document.cookie);
} );
});
Alert Result:
[object Object]=[object Object]; cookieconsent_dismissed=yes