Session variable errors

This is a discussion on "Session variable errors" within the PHP Forum section. This forum, and the thread "Session variable errors are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 12th, 2005, 10:26
Junior Member
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Session variable errors

Hello All,
I have a page that passes a session variable to another page which is then used in an if/else statement. For some reason itsa giving me error messages, and I'm not sure whats up with it.
Heres the page that creates the variable

Code: Select all
<?php
session_start(); // start session
$_SESSION['name'] = 'sport';
?>
and heres the page with the if else statment :

Quote:
<?php
session_start();
$_SESSION['name'];
//$name = 'Jester';
if ( $name == 'sport' ) { ?>
<table>stuff in here</table>
<? } else { ?>
<table>stuff in here</table>
<? } ?>
and finally - here are the error messages that I am getting :

Quote:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\wamp\www\work\hebbingo\site\test.php:11) in c:\wamp\www\work\hebbingo\site\test.php on line 13

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\wamp\www\work\hebbingo\site\test.php:11) in c:\wamp\www\work\hebbingo\site\test.php on line 13
As you've guessed, I'm pretty new to this so I have probably missed something basic - any ideas?

Cheers

Fogo
Reply With Quote

  #2 (permalink)  
Old Dec 12th, 2005, 14:05
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Session variable errors

Your session_start sends our a cookie in the header of the response page and so it must come before any HTML output at all. Move this code to the very top of your PHP file and ensure that the < of the <?php is in row 1, column 1, and it should get rid of the problem. If you need this code to generate outputs, they store those ouputs into a variable and print it out later on.
Reply With Quote
  #3 (permalink)  
Old Dec 16th, 2005, 12:23
Junior Member
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Session variable errors

sweet - thanks man
Reply With Quote
Reply

Tags
session, variable, errors

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing a session variable when clicking a link? Crow555 Classic ASP 0 May 15th, 2008 12:22
[SOLVED] ASP Session Variable Monie Classic ASP 7 Oct 10th, 2007 02:44
Assign string values to integer values of a session variable Andy K Classic ASP 1 Jul 13th, 2005 08:29
problem with Session variable andrew_perez5 Classic ASP 0 Jan 24th, 2005 03:42
session variable Monie Classic ASP 7 Aug 30th, 2004 03:52


All times are GMT. The time now is 01:57.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43