943,935 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 5507
  • PHP RSS
Dec 12th, 2005
0

session variable error

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. session_start(); // start session
  4.  
  5. $_SESSION['name'] = 'sport';
  6.  
  7. ?>

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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fogofogo is offline Offline
8 posts
since Dec 2005
Dec 12th, 2005
0

Re: session variable error

Quote 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 Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. session_start(); // start session
  4.  
  5. $_SESSION['name'] = 'sport';
  6.  
  7. ?>

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.
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005
Dec 16th, 2005
0

Re: session variable error

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fogofogo is offline Offline
8 posts
since Dec 2005
Mar 30th, 2006
0

Re: session variable error

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harzonline is offline Offline
1 posts
since Mar 2006
Apr 12th, 2006
0

Re: session variable error

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jkevinburton is offline Offline
1 posts
since Apr 2006
Oct 14th, 2007
0

Re: session variable error

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vigin is offline Offline
2 posts
since Oct 2007
Oct 14th, 2007
0

Re: session variable error

you must put your session start or your header() function above all the html tags.otherwise,it will have an error like that..
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Oct 15th, 2007
0

Re: session variable error

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vigin is offline Offline
2 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Session variables not carrying over to next page
Next Thread in PHP Forum Timeline: Regular expressions and formatting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC