regarding sessions, in a nutshell
PHP Code:
session_start(); // must be at the TOP of EVERY page you want to use sessions on.
/* in its simplest form. here we set some session variables */
$_SESSION['username'] = 'met';
$_SESSION['age'] = 21;
echo 'My username is ' . $_SESSION['met'] . ' and I am ' . $_SESSION['age'];
// outputs My username is met and I am 21
unset($_SESSION['username']); // unsets the value
echo $_SESSION ['username']);
// outputs nothing.
session_destroy();
/* destroys all sessions and all data is lost */
sessions are used to store data and transfer it across multiple pages (as well as other functions)
some examples: storing the contents of a shopping cart, authenticated user details, page viewing history, user preferences...
you can set a session by assigning it a value literally, or assigning it from $_GET or $_POST (using forms eg)
in your example above when the user submits the form you could set a session value to be equal to the amount they entered, and then use that information on another page later on.
$_SESSION[] is an array, much like $_GET and $_POST, you set and access the values the same way. The main difference is that SESSION will last for the duration of, well, the users session, whereas GET and POST have less scope, i.e only the form(s) they are used in.
the most important thing when dealing with sessions is to remember to put
PHP Code:
<?php
session_start();
/* your script */
at the very top of every page youwant to use sessions in.