-3

Possible Duplicate:
Headers already sent by PHP
Passing PHP Variable From One Dynamic Page to Another

Will appreciate any help on this

Trying to pass on some PHP variables from one page to another .

On page one:

<?php 
session_start(); 
$_SESSION['file'] = $file;
$_SESSION['linecount'] = $linecount;
$_SESSION['priceperpost'] = $priceperpost;
$_SESSION['totalcost'] = $totalcost; 
?>

And then on page two:

<?php
session_start();
$file = $_SESSION['file'];
$linecount = $_SESSION['linecount'];
$priceperpost = $_SESSION['priceperpost'];
$totalcost = $_SESSION['totalcost']; 
?>

This is on a WordPress site and I keep getting an error which says:

"session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at...

Any help would be appreciated.

Community
  • 1
  • 1
  • -1, **DO NOT** repost questions. [We've had this one already](http://stackoverflow.com/q/14147335/168868). – Charles Jan 04 '13 at 00:37

3 Answers3

3

As soon as your script outputs something, headers will be sent to the browser.

So that error means you're printing (echoing?) some other data out before session_start();.

Are you printing anything prior to session_start()? Are you including a file before session_start()? AS that file may be printing something.

0

You are sending some data (even whitespace can be the culprit) before the session_start() call.

Make sure <?php is the absolutely first thing in the script.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
0

The session_start() function has been called after there has been some output to the browser. At that point, the headers are already sent to the browser, and PHP cannot modify then anymore. Which is what session_start() needs to do. Thus, make sure there is no text send to the browser (which means, no echo or print, and no text outside of <?php ?> blocks, before the call to the session_start() function.

kokx
  • 1,706
  • 13
  • 19