write a program in php to set cookies
Question
write a program in php to set cookies
Solution
Sure, here is a simple PHP program to set a cookie:
<?php
// Set a cookie
setcookie("test_cookie", "test_value", time() + 3600, '/'); // expires after 1 hour
?>
<html>
<body>
<?php
// Check if the cookie has been set
if(count($_COOKIE) > 0) {
echo "Cookies are enabled.";
} else {
echo "Cookies are disabled.";
}
?>
</body>
</html>
This program sets a cookie named "test_cookie" with the value "test_value". The cookie will expire after 1 hour. The '/' parameter means that the cookie will be available throughout the entire domain.
After setting the cookie, the program checks if the cookie has been set by counting the number of elements in the $_COOKIE array. If the count is greater than 0, it means that cookies are enabled. Otherwise, cookies are disabled.
Similar Questions
Which of the following function is used to set cookie in PHP?Group of answer choicesNone of the abovesetcookie()makecookie()createcookie()
What are cookies?1 分Pieces of code that store information about a websiteTypes of malware that can damage computersSmall files stored on computers that contain information about usersPrograms that enable users to access websites
__________are a combination of a server-side cookie and a client-side cookieSelect one:a.Sessionsb.Cookiesc.$Sessionsd.$_Sessions
Role of Cookies
JavaScript can create, read, and delete cookies with the ___ property of document object.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.