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

Web Technology Lab Report 5

The document discusses using sessions and cookies in PHP. It shows code to create a session by setting session variables for username, address, and a logged in status. It then checks the session values. It also shows code to create a cookie for username and check if the cookie is set. The summary provides the essential information about setting and checking session variables and cookies in 3 sentences.

Uploaded by

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

Web Technology Lab Report 5

The document discusses using sessions and cookies in PHP. It shows code to create a session by setting session variables for username, address, and a logged in status. It then checks the session values. It also shows code to create a cookie for username and check if the cookie is set. The summary provides the essential information about setting and checking session variables and cookies in 3 sentences.

Uploaded by

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

Web Technology Lab Report 5

Submitted By:
Ayush Manandhar
BCA 3rd Semester
Roll no: 7
Create a session.
<?php

session_start();

$_SESSION["username"] = "spidey";
$_SESSION["address"] = "Nepal";
$_SESSION["loggedIn"] = true;

echo "Session Variables are set";

?>

Check the session.


<?php

session_start();

if($_SESSION["loggedIn"]){
echo "Hello " . $_SESSION["username"];
echo "<br>";
echo "You live in " . $_SESSION["address"];
}else{
echo "session data not found";
}

?>
Create a cookie.

<?php
$cookiename = "username";
$cookiedvalue="spidey";
setcookie($cookiename, $cookiedvalue, time() + (20), "/");
?>

Check the cookie.


<?php
if(isset($_COOKIE["username"])){
echo "cookie name with value: ". $_COOKIE["username"];

}
else{
echo "Error";
}
?>

You might also like