codegurukool.com · Free coding tutorials & online compiler

Home › PHP Tutorial › PHP cookies and sessions

PHP cookies and sessions

Remember a visitor between pages.

A cookie is stored in the browser (setcookie). A session stores data on the server and gives the browser only an id. Call session_start() before any output, then use $_SESSION.

Example code

<?php
session_start();
$_SESSION["user"] = "Ada";
echo "Logged in as " . $_SESSION["user"];
?>

Run this code in the online editor

← PHP date and timePHP JSON →