CSE3002 – Internet and Web Programming Solved

$ 20.99
Category:

Description

ISHAAN OHRI
18BC E0265

Question:
Write a PHP program to demonstrate the concept of Session Management and Cookies
1. Create a cookie with a value of username and his emailId.The cookie should expire in 3 days.Check whether the cookie is present in the website,when the user enters his username, the emailed should be given by the cookies.
2. Perform the following operations:
i. Create a cookie.Check whether the cookie is enabled or not. Print the
status. ii. Delete the created cookie before an hour
iii. Check whether the cookie is disabled or not. Print the status
C ode:
index.php

<html>
<body>
<form action=”page.php” method=”post”>
<p> Username: <input name=”username” type=”text” value=”
<?php
if(isset($_COOKIE[“username”])) {
echo $_COOKIE[“username”]; } ?>” class=”input-field”></p>
<p>Email: <input name=”email” type=”email” value=”
<?php if(isset($_COOKIE[“email”])) {
echo $_COOKIE[“email”]; } ?>” class=”input-field”>
</p>
<p><input type=”checkbox” name=”remember” /> Remember me </p>
<p><input type=”submit” value=”Login”></span></p> </form>
<p><a href=”page.php”> Go to Login Page </a></p>
</body>
</html>

page.php

<?php if(!empty($_POST[“remember”])) {
setcookie (“username”,$_POST[“username”],time()+ 86400*3); setcookie (“email”,$_POST[“email”],time()+ 86400*3); echo “Cookies Set Successfully”; } else { setcookie(“username”,””); setcookie(“email”,””); echo “Cookies Not Set”; }
?>

delete.php

<!DOCTYPE html>
<?php
setcookie(“user”, “”, time() – 3600);
?>
<html>
<body> <?php
echo “Cookie ‘user’ is deleted.”;
?>
</body>
</html>

cookie.php

<?php
setcookie(“test_cookie”, “test”, time() + 3600, ‘/’);
?>
<html>
<body> <?php
if(count($_COOKIE) > 0) { echo “Cookies are enabled.”;
} else {
echo “Cookies are disabled.”;
}
?>
</body>
</html>

Output:

Reviews

There are no reviews yet.

Be the first to review “CSE3002 – Internet and Web Programming Solved”

Your email address will not be published. Required fields are marked *