<aside> 💡
HTTP is a stateless and forgetful protocol. To save state in PHP, cookies and sessions are used.
</aside>
<aside> 💡
Cookies store all information on client
</aside>
<?php
if (isset($_COOKIE["count"])) {
$value = $_COOKIE["count"] + 1;
} else {
$value = 1;
}
setcookie("count", $value, time() + 5, "/");
?>
<html>
<head>
<title>Testing Cookies</title>
</head>
<body>
<h1>Cookies</h1>
<p>Your visit count is <?php echo $value; ?></p>
</body>
</html>
<aside> 💡
temp
folderPHPSESSID
is stored as a cookie on client
</aside><?php
session_start();
if (isset($_SESSION["count"])) {
$_SESSION["count"]++;
} else {
$_SESSION["count"] = 1;
}
?>
<html>
<head>
<title>Testing Cookies</title>
</head>
<body>
<h1>Cookies</h1>
<p>Your visit count is <?php echo $_SESSION["count"]; ?></p>
</body>
</html>
Example of session data stored on /var/lib/php/sessions
in Ubuntu (temp
in XAMPP root)
count|i:19;
<aside> 💡
What is a framework?
Starting point for a project with minimum requirements such as authentication, functioning as a hello world for your own project.
</aside>
<aside> 💡
Composer is a PHP dependency manager using https://packagist.com repository
</aside>