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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!