0% found this document useful (0 votes)
241 views

PHP Practical No.13

The document provides code examples to demonstrate how to create, modify, delete cookies and create and destroy sessions in PHP. The cookie example sets, modifies, and then deletes a cookie called "mycookie" to show how its value changes and is eventually removed. The session example creates a session variable called "name", outputs its value, then destroys the session, showing that the variable is no longer set.

Uploaded by

Abhishek Jaikar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

PHP Practical No.13

The document provides code examples to demonstrate how to create, modify, delete cookies and create and destroy sessions in PHP. The cookie example sets, modifies, and then deletes a cookie called "mycookie" to show how its value changes and is eventually removed. The session example creates a session variable called "name", outputs its value, then destroys the session, showing that the variable is no longer set.

Uploaded by

Abhishek Jaikar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Code:

1. Write the program to create, modify & delete cookies.


<?php
if (isset($_COOKIE['mycookie'])) {
echo "The value of mycookie is: " . $_COOKIE['mycookie'] . "<br>";
} else {
echo "The cookie 'mycookie' is not set.<br>";
}
setcookie('mycookie', 'Hello, World!', time() + (86400 * 30), "/");
$_COOKIE['mycookie'] = 'Manish7';
if (isset($_COOKIE['mycookie'])) {
echo "The value of mycookie is: " . $_COOKIE['mycookie'] . "<br>";
}
setcookie('mycookie', '', time() - 3600, "/");
if (isset($_COOKIE['mycookie'])) {
echo "The cookie 'mycookie' is still set.";
} else {
echo "The cookie 'mycookie' has been deleted.";
}
?>
Output:

2. Write a program to create & destroy session.


<?php
session_start();
$_SESSION["name"] = "Manish";
echo "Hello, " . $_SESSION["name"] . "!<br>";
session_destroy();
if (isset($_SESSION["name"])) {
echo "Session variable still exists.";
} else {
echo "Session variable has been destroyed.";
}
?>
Output:

You might also like