php practical 13
php practical 13
Data Storage: Cookies store data on the client-side, whereas sessions store data on the server-
side. This means that cookies can be accessed and modified by the user, while session data is
more secure and can only be accessed by the server.
Data Size: Cookies have a size limit of around 4KB, while session data can be much larger.
Expiration: Cookies have an expiration time that can be set, so they can persist across
multiple sessions. Session data, on the other hand, is destroyed when the session ends (either
because the user logs out or the session times out).
Security: Session data is more secure than cookies because it's stored on the server and can't
be tampered with by the user.
Accessibility: Cookies can be accessed from any browser on any device, while session data
is only accessible on the server that created it.
4. What is the difference
between session_unregister
() and session_unset()?
The session_unregister() and session_unset() functions are both used to clear session
variables in PHP, but they work in slightly different ways.
This default value can be changed by modifying the session.gc_maxlifetime directive in the
php.ini configuration file or by using the ini_set() function in your PHP code to set the value
dynamically.
6. Is it possible to destroy a
cookie ()?
Yes it is possible you need set the expiration date of the cookie.
Exercise Related Question
1. Write a program that demonstrate use of cookies
<?php
// Set a cookie with a name, value, and expiration time of one
hour
setcookie("username", "John Doe", time()+3600);
if(isset($_SESSION['count'])) {
$_SESSION['count']++;
} else {
$_SESSION['count'] = 1;
}