Ho un problema riguardo alle sessioni.


Il seguente codice php (application.php) è incluso in tutte le mie pagine php:

<?
/* application.php */
/* turn on verbose error reporting (15) to see all warnings and errors */
error_reporting(15);

/* define a generic object */
class object {};

$CFG = new object;

/* database configuration */
$CFG->dbhost = "localhost";
$CFG->dbname = "system_mymarket";
$CFG->dbuser = "nome_utente";
$CFG->dbpass = "password";

/* directory configuration, if all your mymarket files are in one directory
* you probably only need to set the wwwroot variable. valid examples are:
*
* $CFG->wwwroot = "http://myserver.com/mymarket";
* $CFG->wwwroot = "http://localhost/mymarket";
*
* do not include the trailing slash. dirroot is the physical path on your
* server where mymarket can find it's files. for more security, it is
* recommended that you move the libraries and templates ($CFG->libdir
* and $CFG->templatedir) outside of your web directories.
*/
$CFG->wwwroot = "/mymarket_IT";
$CFG->dirroot = dirname(__FILE__);
$CFG->templatedir = "$CFG->dirroot/templates";
$CFG->libdir = "$CFG->dirroot/lib";
$CFG->imagedir = "$CFG->wwwroot/images";
$CFG->icondir = "$CFG->imagedir/icons";
$CFG->bannerdir = "$CFG->imagedir/banners";
$CFG->artdir = "$CFG->imagedir/articoli";
$CFG->support = "aaa@sito.it";
$CFG->version = "1.72";
$CFG->sessionname = "mymarket_IT";

/* extended configuration */
$CFG->showsponsor = true; // enabled banner advertising
$CFG->currency = "€";
$CFG->currencyfirst = true; // show the currency symbol before the price tag
$CFG->language = "IT"; // show the language constant

/* define database error handling behavior, since we are in development stages
* we will turn on all the debugging messages to help us troubleshoot */
$DB_DEBUG = true;
$DB_DIE_ON_FAIL = true;

/* load up standard libraries */
require("$CFG->libdir/stdlib.php");
require("$CFG->libdir/dblib.php");
require("$CFG->libdir/mymarket.php");
require("$CFG->libdir/cart.php");


/* setup some global variables */
$ME = qualified_me();

/* start up the sessions, to keep things simple we just have two
* variables, USER containing user information and CART containing
* the user's shopping cart. */
ini_set("session.name", $CFG->sessionname);
session_start();
session_register("USER");
session_register("CART");

/* initialize the USER object if necessary */
if (! isset($_SESSION["USER"])) {
$_SESSION["USER"] = array();
}

/* initialize the CART object if necessary */
if (! isset($_SESSION["CART"])) {
$_SESSION["CART"] = new Cart;
}

$USER = &$_SESSION["USER"];
$CART = &$_SESSION["CART"];

/* connect to the database */
db_connect($CFG->dbhost, $CFG->dbname, $CFG->dbuser, $CFG->dbpass);
?>


Quando voglio connettermi chiamo il seguente codice di login (login.php):

<?
/* login.php */

include("application.php");

/* form has been submitted, check if it the user login information is correct */
if (match_referer() && isset($_POST)) {
$user = verify_login($_POST["username"], $_POST["password"]);

if ($user) {
$USER["user"] = $user;
$USER["ip"] = $_SERVER["REMOTE_ADDR"];

/* if wantsurl is set, that means we came from a page that required
* log in, so let's go back there. otherwise go back to the main page */
$goto = empty($USER["wantsurl"]) ? $CFG->wwwroot : $USER["wantsurl"];

header("Location: $goto");
die;

} else {
$errormsg = "Dati non validi, prego riprovare";
$frm["username"] = $_POST["username"];
}
}

include("$CFG->templatedir/login_form.php");

/************************************************** ****************************
* FUNCTIONS
************************************************** ***************************/

function verify_login($username, $password) {
/* verify the username and password. if it is a valid login, return an array
* with the username, firstname, lastname, and email address of the user */

if (empty($username) || empty($password)) return false;

$qid = db_query("
SELECT username, firstname, lastname, email, priv, phone, address
FROM users
WHERE username = '$username' AND password = '" . md5($password) . "'
");

return db_fetch_array($qid);
}

?>


Quando mi voglio disconnettere dalla sessione chiamo il seguente codice per il logout (logout.php):

<?
/* logout.php */

include("application.php");

unset($USER);
unset($_SESSION["USER"]);
redirect("$CFG->wwwroot", "Utente Disconnesso", 1);
?>


Il problema si verifica quando io richiamo il login per riconnettermi
è il seguente:

Notice: Array to string conversion in /home/system/public_html/mymarket_IT/login.php on line 16

ovvero in corrispondenza alla riga 16 c'è il seguente codice:
$USER["user"] = $user;

Warning: Cannot modify header information - headers already sent by (output started at /home/system/public_html/mymarket_IT/login.php:16) in /home/system/public_html/mymarket_IT/login.php on line 23

può aiutarmi a capire l'errore.
Grazie Antonio Martinelli