$_SESSION woes...

A

Anonymous

Guest
I am placing this at the top of the page where I would like to assign and use my $_SESSION variable:

Code:
 // start the session 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 

$username = $_POST['username']; 

// Register session key with the value 
   $_SESSION['username'] = $username;

But my database queries are coming out screwy, probably because the script doesn't recognize "$_SESSION['username'] = $username"....

And I get these PHP errors:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php:7) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php on line 18

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php:7) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php:7) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/shopping_cart.php on line 19

for these two lines respectively:

Code:
 session_start(); 
header("Cache-control: private"); //IE 6 Fix


What is the issue here?...thanks. :)
__________________
R.J.
http://www.mediamogulsweb.com
 
The trouble is that you're sending output (i.e. text, HTML, whitespace, or PHP echo/print/etc.) before your headers. Any function which affects the headers (header(), cookies, sessions, etc.) must be done before you make any output. In you're case, it looks like you're sending output on line 7 of shopping_cart.php.
 
Back
Top