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

Practical No. 13 Name:-Sakshi Kamble Batch:-T2 Roll No.: - 3222 1. Write A Program To Create, Modify and Delete A Cookie. Code

The document contains two practical programming exercises related to cookie and session management in PHP. The first exercise demonstrates how to create, modify, and delete a cookie, while the second exercise shows how to start and destroy a session. Each section includes HTML and PHP code snippets to illustrate the concepts.
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)
16 views2 pages

Practical No. 13 Name:-Sakshi Kamble Batch:-T2 Roll No.: - 3222 1. Write A Program To Create, Modify and Delete A Cookie. Code

The document contains two practical programming exercises related to cookie and session management in PHP. The first exercise demonstrates how to create, modify, and delete a cookie, while the second exercise shows how to start and destroy a session. Each section includes HTML and PHP code snippets to illustrate the concepts.
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

Name :-Sakshi Kamble Batch :- T2 Roll No. :- 3222

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

Code :-

<!DOCTYPE html> }
<html> // Delete a cookie
<head> if(isset($_GET['delete_cookie'])) {
<title>Cookie Management</title> setcookie("user", "", time() - 3600, "/"); //
</head> Expire the cookie
<body> echo "Cookie deleted.";
<h2>Cookie Management</h2> }
<?php ?>
// Create a cookie <p>Cookie Value: <?php echo
setcookie("user", "Admin", time() + 3600, isset($_COOKIE['user']) ? $_COOKIE['user'] :
"/"); // Expires in 1 hour "No cookie set"; ?></p>
// Modify a cookie <a href="?delete_cookie=1">Delete
if(isset($_COOKIE['user'])) { Cookie</a>
setcookie("user", "NewAdmin", time() + </body>
3600, "/"); // Modify cookie value </html>

Output :-

2. Write a program to start and destroy a session.

Code :-

<!DOCTYPE html> session_start(); // Start session


<html> // Set session variable
<head> $_SESSION["username"] = "Admin";
<title>Session Management</title> echo "Session started. Username: " .
</head> $_SESSION["username"];
<body> // Destroy session
<h2>Session Management</h2> if(isset($_GET['destroy_session'])) {
<?php
session_unset(); // Unset session <br>
variables <a href="?destroy_session=1">Destroy
session_destroy(); // Destroy session Session</a>
echo "<p>Session destroyed.</p>"; </body>
} </html>
?>

Output :-

You might also like