[thelist] PHP sessions

Jackson Yee jyee at vt.edu
Wed Jul 31 15:42:00 CDT 2002


----- Original Message -----
From: <NanHarbisonSmith at aol.com>
To: <thelist at lists.evolt.org>
Sent: Wednesday, July 31, 2002 16:23
Subject: [thelist] PHP sessions


> Hi all,
> I am just learning about session with PHP. The book I am looking at says
that
> you have to put the session information before any other information, and
> then it gives an example, putting the script above the head tag. But where
> does it go with respect to the DTD? Before it?

It really doesn't matter where you put your code as long as you call
session_start() before you output any actual HTML, just like use of the
header() function.  Having a block of code that says

<?php
session_start();
?>

at the top of your page is usually the way to go though.  Just make sure that
you call session_start() on every single page to make sure that your session
variables are persisted.

> Also, when you register a session, with the two pieces of data, the book
uses
> username and account. Does it matter what the account value actually is?

Values don't matter.  $_SESSION is an array that you could store anything in.
You could do

$_SESSION['foo'] = 'bar';

and then do

echo $_SESSION['foo'];

on the next page, displaying 'bar'.  It's up to you to name the variable and
give it a value.

The official documentation for PHP has a good overview with user comments for
sessions at

http://www.php.net/manual/en/function.session-start.php

Intrinsic session support is one of my favorite features of PHP over other
environments, and has proven valuable many times in the past.

Regards,
Jackson Yee
jyee at vt.edu
http://www.jacksonyee.com/




More information about the thelist mailing list