Simple Sessions

To use sessions on a page, you must have this session_start(); That must appear before anything is output to the user so, echo 'Help!'; session_start(); would output errors. session_start(); Is fine since nothing is sent to the user,

Bla Bla Bla <? session_start(); ?>

&

To use sessions on a page, you must have this session_start(); That must appear before anything is output to the user so, echo 'Help!'; session_start(); would output errors. session_start(); Is fine since nothing is sent to the user,

Bla Bla Bla <? session_start(); ?>

&

<? session_start(); ?>

are both wrong, Nothing (even whitespaces should be sent to the user).

Now we have that out of the way, we can move onto doing something with sessions. To define a session we use:

$_SESSION['mysession'] = 'BLA';

Now on the next page we will be able to access that information, Useful to see which page a user came from. To access the Session ID, you can use session_id(); , for example:

$yoursession = session_id(); echo '<a href="?home.php?'.$yoursession.'">Home</a>';

If you do not want to add any info to a session but you wish to create it, you can use session_register("mysession"); If you want to clear ALL sessions use, session_destroy() That removes all sessions and all data. Simple huh? You now should understand the basics of Sessions.

<? session_start(); ?>