Question
How can I convert these JavaScript functions into a PHP class so that it can be inserted to a .php file? function setCookie(cname, cvalue, exdays)
How can I convert these JavaScript functions into a PHP class so that it can be inserted to a .php file?
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 + ";path=/"; }
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 ""; }
function checkCookie(cname) { var value = getCookie(cname); if (value != "") { alert("Cookie Name = " + cname + "Value = " + value); } else { value = prompt("Please enter your cookie :"+cname+" Value", ""); if (value != "" && value != null) { setCookie(cname, value, 365); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started