PHP Session Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheFisherman
Forum Newbie
Posts: 8
Joined: Fri Nov 14, 2003 6:43 pm
Location: Plano, Texas

PHP Session Variables

Post 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.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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.
TheFisherman
Forum Newbie
Posts: 8
Joined: Fri Nov 14, 2003 6:43 pm
Location: Plano, Texas

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

The session start must come before any input to the browser. This includes whitespace. Hope that helps.
Post Reply