Call this code mypage.php
The first thing we do with this code, is open the session using session_start(). We then set our first session variables (color, size and shape) to be red, small and round respectively.
<?php // this starts the session session_start(); // this sets variables in the session $_SESSION['color']='red'; $_SESSION['size']='small'; $_SESSION['shape']='round'; print "Done"; ?>
Just like with our cookies, the session_start() code must be in the header and you can not send anything to the browser before it. It's best to just put it directly after the <?php to avoid potential problems.
So how will it know it's me? Most sessions set a cookie on your computer to uses as a key... it will look something like this: 350401be75bbb0fafd3d912a1a1d5e54. Then when a session is opened on another page, it scans your computer for a key. If there is a match, it accesses that session, if not it starts a new session for you.