if you want, you can let php take care of the session id. just calling session_start() will put into motion all manner of php functionality for handling sessions. do this:
<?
phpinfo();
?>
take a peek at the session-related settings like enable-trans-sid or session autostart.
for your pages that want to use sessions, you can just do something like this:
<?
// SID is a constant auto-defined in php for me
// it may or may not be set depending on what
// functions you have called, whether cookies are
// on in the user's browser
// and what PHP INI settings are
echo "SID BEFORE SESSION START:" . SID . "<br>";
session_start();
echo "SID AFTER SESSION START:" . SID;
// the first time this page is loaded, this var should be empty
echo "\$_SESSION['var'] = " . $_SESSION['var'];
// but we put it into session so we can look at it on the next refresh
$_SESSION['var'] = "I can store whatever i want here.";
?>
You'll see that the first time you load the page, SID is undefined before you start the session.
Once you start the session, it contains both the name that PHP is using for your session and your current session id. if enable-trans-sid is on, SID will be automatically appended to relative URL links on your site when cookies don't work so that the session id gets from page to page. if you read about this you will realize that this presents a security risk because session ids can be stolen pretty easily from a URL.
the session variable is empty on the first page viewing.
if you refresh the page, a couple of things should happen:
1) if cookies are on, SID will be empty because the session id is propagated through cookies.
2) if sessions are working properly, your session var should now hold what you assigned on the previous page. it will stay defined until you UNSET it or change it to something else or until your session ends or somehow the session id fails to get propagated.