Page 1 of 1

PHP Session Variables

Posted: Sat Nov 15, 2003 8:22 pm
by TheFisherman
I am new to PHP and cannot find out how to use session variables like I am used to in ASP. Any help would be appreciated.

Posted: Sat Nov 15, 2003 9:23 pm
by Paddy
Seeing as you know ASP you probably just want the syntax for using sessions?

Code: Select all

<?php
session_start();
$_SESSION['somevar'] = "blah";
$anothervar = $_SESSION['somevar'];
echo ($anothervar);
?>
Would print blah to the screen. Placing session_start(); at the top of any php file would mean that $anothervar = $_SESSION['somevar']; would work in it as long as somevar has been set prior.

Hope that helps.

Posted: Sat Nov 15, 2003 10:00 pm
by TheFisherman
I get the following message when I put the session_start(); in the php file:

Warning: Cannot send session cache limiter - headers already sent (output started at d:\inetpub\tanstafl.com\rgc\test01.php:2) in d:\inetpub\tanstafl.com\rgc\test01.php on line 3

Posted: Sat Nov 15, 2003 10:21 pm
by Paddy
The session start must come before any input to the browser. This includes whitespace. Hope that helps.