PDA

View Full Version : Noob Question



Shotgun Ninja
11-21-2007, 04:14 PM
Call me a noob. It's true.

How exactly does the session_start and other such functions work? :confused: I'm sure it's incredibly obvious, but I'm kinda strapped for time and resources. :o

boogyman
11-21-2007, 04:18 PM
you need to declare the session at the very top of your page before anything is parsed / the session variables used


<?php
session_start();

$_SESSION['user'] = $_SERVER['USER_AGENT'];
?>

Shotgun Ninja
11-21-2007, 04:29 PM
Thanks, embarrassed. :o

boogyman
11-21-2007, 04:36 PM
don't be... it wasnt too long ago that I had the very same question. thats the beauty of learning; we dont start with all the knowledge in the world :)

djr33
11-21-2007, 09:29 PM
session_start() must be called before anything else on the page (ie output). To continue the session (at least to be sure it continues) you must include session_start() on every related page on the site.

Once the session is enabled, $_SESSION[...] will be available on any page and data will be carried through continuously. It will expire after perhaps 15 minutes of inactivity, closing the browser, etc. A "session" describes it well.

To end a session, it's a bit harder-- look at session_destroy() and related functions on php.net.