Last time, we mostly looked at the difference between cookies and sessions (relating to PHP-provided sessions.
This time, let’s go a bit heavy on the code, and learn about things to watch out for during implementation.
First, whether for cookies or sessions, at the end you will output a Cookie (HTTP response header).
Thus, while it depends on your php. ini’s settings (output_buffering), writing code like below can get you an error that reads ‘Warning: session_start (): Cannot start session when headers already sent in’ or ‘Warning: Cannot modify header information — headers already sent by’.
(Please see below for the rest)