0% found this document useful (0 votes)
10 views2 pages

PHP Practical No.13 Outputs

The document provides PHP code examples for creating, modifying, and deleting cookies, as well as starting and destroying sessions. It includes specific actions for each operation and outputs demonstrating the results of these actions. The examples show how to manage user data through cookies and sessions effectively.

Uploaded by

ARYAN MOHADE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

PHP Practical No.13 Outputs

The document provides PHP code examples for creating, modifying, and deleting cookies, as well as starting and destroying sessions. It includes specific actions for each operation and outputs demonstrating the results of these actions. The examples show how to manage user data through cookies and sessions effectively.

Uploaded by

ARYAN MOHADE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL No.

13
Outputs

Q.1 Write a program to create, modify and delete a cookie

<?php
$action = $_GET['action'] ?? '';

// Create cookie
if ($action == 'create') {
setcookie("user", "Aryan", time() + 3600); // 1 hour
echo "Cookie 'user' created with value: Aryan";
}

// Modify cookie
elseif ($action == 'modify') {
setcookie("user", "Mohade Sir", time() + 3600); // update value
echo "Cookie 'user' modified to: Mohade Sir";
}

// Delete cookie
elseif ($action == 'delete') {
setcookie("user", "", time() - 3600); // expired
echo "Cookie 'user' deleted";
}

// Display current cookie value


else {
if (isset($_COOKIE['user'])) {
echo "Current cookie value: " . $_COOKIE['user'];
} else {
echo "No cookie found.";
}
}
?>
PRACTICAL No.13
Outputs
Output

After create:
Cookie 'user' created with value: John
After modify:
Cookie 'user' modified to: Thomas alva edison
After delete:
Cookie 'user' deleted
On load (if cookie exists):
Current cookie value: John

Q. Write a program to start and destroy session.

Ans.

<?php

// Start session

session_start();

$_SESSION["user"] = "Aryan";

echo "Session started. User = " . $_SESSION["user"] . "<br>";

// Destroy session Output


session_destroy();

echo "Session destroyed."; Session started. User = John Doe


?> Session destroyed.

You might also like