Cookies and Sessions in PHP

 Cookies and Sessions in PHP


PHP provides built-in support for managing user sessions and cookies. Sessions can be used to store user data on the server, while cookies can be used to store data on the user's browser.

Example:


php


// set a cookie

$name = "John";

setcookie("user", $name, time() + (86400 * 30), "/");


// get a cookie

echo $_COOKIE["user"];


// start a session

session_start();

$_SESSION["username"] = "John";


// access session data

echo $_SESSION["username"];

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...