User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,720 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,103 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3701 | Replies: 7
Reply
Join Date: Dec 2005
Posts: 8
Reputation: fogofogo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
fogofogo fogofogo is offline Offline
Newbie Poster

session variable error

  #1  
Dec 12th, 2005
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

<?php

session_start(); // start session

$_SESSION['name'] = 'sport';

?>

and heres the page with the if else statment :

<?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 :

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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 494
Reputation: techniner is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 18
techniner techniner is offline Offline
Posting Pro in Training

Re: session variable error

  #2  
Dec 12th, 2005
Originally Posted by fogofogo
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

<?php

session_start(); // start session

$_SESSION['name'] = 'sport';

?>

and heres the page with the if else statment :



and finally - here are the error messages that I am getting :



As you've guessed, I'm pretty new to this so I have probably missed something basic - any ideas?

Cheers

Fogo


One of two things are happening.. but to correct the error you can:

output_buffering = Off

Toggle this to produce the error.

Most liekly you are using an include to like header.php" that is outputing the session data already.

You cannot resend the header infomation once it has been sent already.
Did my post help?
Visit Little Jon's Web Portal


Generate Traffic with Maximum Traffic Software
Reply With Quote  
Join Date: Dec 2005
Posts: 8
Reputation: fogofogo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
fogofogo fogofogo is offline Offline
Newbie Poster

Re: session variable error

  #3  
Dec 16th, 2005
Originally Posted by techniner
One of two things are happening.. but to correct the error you can:

output_buffering = Off

Toggle this to produce the error.

Most liekly you are using an include to like header.php" that is outputing the session data already.

You cannot resend the header infomation once it has been sent already.

cool - tha nks
Reply With Quote  
Join Date: Mar 2006
Posts: 1
Reputation: harzonline is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
harzonline harzonline is offline Offline
Newbie Poster

Re: session variable error

  #4  
Mar 30th, 2006
check if there is any echo to the browser. also check if there are any whitespace b4 session_start() function.

/* Wrong
<?

session_start();
?>
*/

/*

/* correct way
<?php
session_start();
?>
*/

regards
Reply With Quote  
Join Date: Apr 2006
Location: Kitchener, ON
Posts: 1
Reputation: jkevinburton is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jkevinburton's Avatar
jkevinburton jkevinburton is offline Offline
Newbie Poster

Re: session variable error

  #5  
Apr 12th, 2006
You cannot output any text to the user and then try and do a header() call in PHP. If you do, you will get a headers already sent error.

Hope that helps
Kevin
karancorp.com
kburton@karancorp.com
MSN: kburton@karancorp.com
Reply With Quote  
Join Date: Oct 2007
Posts: 2
Reputation: vigin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vigin vigin is offline Offline
Newbie Poster

Re: session variable error

  #6  
Oct 14th, 2007
HI ALL
I am beginner in php. I have same problem like Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\php\authentication\register_new.php:1) in C:\wamp\www\php\authentication\register_new.php on line 9
. Will you please help me in this stage?

Thanks and Regards
Vigin Kurakar
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 507
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: session variable error

  #7  
Oct 14th, 2007
you must put your session start or your header() function above all the html tags.otherwise,it will have an error like that..
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 2
Reputation: vigin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vigin vigin is offline Offline
Newbie Poster

Re: session variable error

  #8  
Oct 15th, 2007
Here is the code.
<?php
$email = $_POST['email'];
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$passwd2 = $_POST['passwd2'];
require_once('example.php');
session_start();
{
try
{
if (!filled_out($_POST))
{
throw new Exception ('You have not filled the form correctely');
}
if (!valid_email($email))
{
throw new Exception ('That is not valid email address');
}
if ($passwd != $passwd2)
{
throw new Exception ('The passwords which you entered is not match');
}
if (strlen($passwd)<6)
{
throw new Exception ('Your password must be atleast 6 characters');
}
if (strlen($username)>16)
{
throw new Exception ('Your username must be less than 16 characters');
}
register($username, $email, $passwd);
$_SESSION['valid_user'] = $username;

do_html_header("Registration Succssesful");
echo "Your registration was succseesful.Go to members area";
do_html_url('welcome.php', 'Go to that page');

do_html_footer();
}
catch (Exception $e)
{
do_html_header("Problem:");
echo $e -> getMessage();
do_html_footer();
exit;
}
}
?>
Please adivce me what i can do in this.

Thanks and Regards
Vigin Kurakar
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC