OldManRiver
12-02-2008, 08:22 PM
All,
Having a problem with sessions.
I created the following files:
<?php
/*******************************************************************************/
/* File: reg_vars.php Usage: include ('reg_vars.php'); */
/* Author: Nyle E. Davis Create Date: 11/04/08 */
/* Mod by: Nyle E. Davis Mod Date: 12/02/08 */
/* Purpose: Register the Class and Session variable and their values. */
/*******************************************************************************/
/* Mod History: 12/02/08 */
/* Attempt to correct problem with 'session_start();' errors. */
/*******************************************************************************/
if (!class_exists('customer')) include 'classes.inc.php';
if (!function_exists('dbConnect')) include 'dblib.inc.php';
include 'header.inc.php';
$newOrderID = date("ymdHis");
$sesNameID = "C-Wines".date("ymd");
session_name($sesNameID);
if (!session_is_registered ($sesNameID)) {
session_start(); // Moved here 11/24/08 to avoid load issues.
}
$sn = session_name($sesNameID);
$si = session_id();
$tn = $_SESSION['name'];
$ti = $_SESSION['sid'];
echo "SN=> $sn SI=> $si TN=> $tn TI=> $ti <br>";
$login = $_POST["login"];
$passwd = $_POST["passwd"];
if(empty($login) || empty($passwd)) {
unset($status);
} else {
$status = 'logged';
}
if ($status=='logged') {
$auth = "$TRUE";
$l_aid = $login;
$l_pid = $passwd;
$l_sta = $status;
$l_ses = $sesNameID;
$log = new login();
$log->setVar($login, $LOGID);
$log->setVar($passwd, $LOGPD);
$log->setVar($status, $LOGST);
$log->setVar($sesNameID, $LOGSES);
$_SESSION["log"] = $log;
$_SESSION["auth"] = $auth;
dbConnect();
$query = sprintf("select * from customers where userid = %s and passwd = '%s'", $login, $passwd);
$result = dbQuery($query);
$found = dbNRows($result);
if($found==1) {
$cust = new customer();
$basket = array();
$items = array();
$c_aid = dbRes($result, 0, "userid");
$c_nm1 = dbRes($result, 0, "name1");
$c_nm2 = dbRes($result, 0, "name2");
$c_1ad = dbRes($result, 0, "address1");
$c_2ad = dbRes($result, 0, "address2");
$c_zsc = dbRes($result, 0, "state_zip");
$c_tat = dbRes($result, 0, "active");
$c_vid = dbRes($result, 0, "division");
$c_dio = $newOrderID;
$c_pyt = dbRes($result, 0, "price_type");
$cust->setVar($c_aid, $ACCTNUMBER);
$cust->setVar($c_nm1, $ACCTNAME);
$cust->setVar($c_nm2, $ACCTNAME2);
$cust->setVar($c_1ad, $ACCTADDRESS);
$cust->setVar($c_2ad, $ACCTADDRESS2);
$cust->setVar($c_zsc, $ACCTSTATEZIP);
$cust->setVar($c_tat, $ACCTACTIVE);
$cust->setVar($c_vid, $ACCTDIVISION);
$cust->setVar($c_dio, $ORDERID);
$cust->setVar($c_pyt, $ACCTTYPE);
$_SESSION["cust"] = $cust;
$_SESSION["basket"] = $basket;
$_SESSION["items"] = $items;
$_SESSION["custItems"] = $custItems;
} // end if $found
} // end if $status
session_write_close();
?>
<?php
/*******************************************************************************/
/* File: get_vars.php Usage: include ('get_vars.php'); */
/* Author: Nyle E. Davis Create Date: 11/04/08 */
/* Mod by: Nyle E. Davis Mod Date: 12/02/08 */
/* Purpose: Get the registered Class and Session variables and their values. */
/*******************************************************************************/
/* Mod History: 12/02/08 */
/* Attempt to correct problem with 'session_start();' errors. */
/*******************************************************************************/
// session_start();
if (!class_exists('customer')) include 'classes.inc.php';
if (class_exists('customer')) {
$cust = new customer();
$c_cid = $cust->getVar($ACCTNUMBER);
$c_div = $cust->getVar($ACCTDIVISION);
$c_nam = $cust->getVar($ACCTNAME);
$c_nm2 = $cust->getVar($ACCTNAME2);
$c_ad1 = $cust->getVar($ACCTADDRESS);
$c_ad2 = $cust->getVar($ACCTADDRESS2);
$c_csz = $cust->getVar($ACCTSTATEZIP);
$c_typ = $cust->getVar($ACCTTYPE);
$c_oid = $cust->getVar($ORDERID);
}
if (!$cust->getVar($ACCTNUMBER)) {
$cust = $_SESSION['cust'];
foreach ($cust as $key => $val) {
// echo "K=> $key V=> $val <br>";
switch($key) {
case 'acctNumber':
$c_cid = $val;
break;
case 'acctDivision':
$c_div = $val;
break;
case 'acctName':
$c_nm1 = $val;
break;
case 'acctName2':
$c_nm2 = $val;
break;
case 'acctAddress':
$c_ad1 = $val;
break;
case 'acctAddress2':
$c_ad2 = $val;
break;
case 'acctStateZip':
$c_csz = $val;
break;
case 'acctType':
$c_typ = $val;
break;
case 'orderID':
$c_oid = $val;
break;
} // end switch
} // end foreach
} // end if !$cust
$cust_inf = array('acctNumber'=>$c_cid,'acctDivision'=>$c_div,'acctName'=>$c_nm1,
'acctName2'=>$c_nm2,'acctAddress'=>$c_ad1,'acctAddress2'=>$c_ad2,
'acctStateZip'=>$c_csz,'acctType'=>$c_typ,'orderID'=>$c_oid);
$_SESSION['$cust_inf'] = $cust_inf;
if (class_exists('login')) {
$log = new login();
$l_uid = $log->getVar($LOGID);
$l_pwd = $log->getVar($LOGPD);
$l_sta = $log->getVar($LOGST);
$l_ses = $log->getVar($LOGSES);
}
if (!$log->getVar($LOGID)) {
$log = $_SESSION['log'];
foreach ($log as $key => $val) {
// echo "K=> $key V=> $val <br>";
switch($key) {
case 'log_id':
$l_uid = $val;
break;
case 'log_pd':
$l_pwd = $val;
break;
case 'log_status':
$l_sta = $val;
break;
case 'log_session':
$l_ses = $val;
break;
} // end switch
} // end foreach
}
$log_inf = array('log_id'=>$l_uid,'log_pd'=>$l_pwd,'log_status'=>$l_sta,
'log_session'=>$l_ses);
$_SESSION['$log_inf'] = $log_inf;
session_write_close();
include 'reg_vars.php';
?>
I'm developing on Windows box running WAMP, but host test site on Ubuntu 7.10 server. Production environment is RHE4, so have to ensure PHP4 compatibility.
Code works fine on dev box, but get the errors:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/test/html/reg_vars.php:15) in /var/www/test/html/reg_vars.php on line 9
when running on test box.
I put in session test (lines 17-19) to attempt making sure the session only opens once if (!session_is_registered ($sesNameID)) {
session_start(); // Moved here 11/24/08 to avoid load issues.
}
but still get the errors. I even changed all my 'include ()' statements for these files to 'include_once()'.
I have to call the reg_vars and get_vars routines several times as my shopping cart is housed in an IFRAME and vars do not pass well without these being re-called. I had to add the 'session_write_close();' commands to each file, as the IFRAME would not work without them.
Not sure what to look for next. Wondering what I need to add/edit to fix this? Would changing my 'include()' statements to 'require()' statement resolve this since there is less error checking?
Will appreciate all your help.
Thanks!
OMR
Having a problem with sessions.
I created the following files:
<?php
/*******************************************************************************/
/* File: reg_vars.php Usage: include ('reg_vars.php'); */
/* Author: Nyle E. Davis Create Date: 11/04/08 */
/* Mod by: Nyle E. Davis Mod Date: 12/02/08 */
/* Purpose: Register the Class and Session variable and their values. */
/*******************************************************************************/
/* Mod History: 12/02/08 */
/* Attempt to correct problem with 'session_start();' errors. */
/*******************************************************************************/
if (!class_exists('customer')) include 'classes.inc.php';
if (!function_exists('dbConnect')) include 'dblib.inc.php';
include 'header.inc.php';
$newOrderID = date("ymdHis");
$sesNameID = "C-Wines".date("ymd");
session_name($sesNameID);
if (!session_is_registered ($sesNameID)) {
session_start(); // Moved here 11/24/08 to avoid load issues.
}
$sn = session_name($sesNameID);
$si = session_id();
$tn = $_SESSION['name'];
$ti = $_SESSION['sid'];
echo "SN=> $sn SI=> $si TN=> $tn TI=> $ti <br>";
$login = $_POST["login"];
$passwd = $_POST["passwd"];
if(empty($login) || empty($passwd)) {
unset($status);
} else {
$status = 'logged';
}
if ($status=='logged') {
$auth = "$TRUE";
$l_aid = $login;
$l_pid = $passwd;
$l_sta = $status;
$l_ses = $sesNameID;
$log = new login();
$log->setVar($login, $LOGID);
$log->setVar($passwd, $LOGPD);
$log->setVar($status, $LOGST);
$log->setVar($sesNameID, $LOGSES);
$_SESSION["log"] = $log;
$_SESSION["auth"] = $auth;
dbConnect();
$query = sprintf("select * from customers where userid = %s and passwd = '%s'", $login, $passwd);
$result = dbQuery($query);
$found = dbNRows($result);
if($found==1) {
$cust = new customer();
$basket = array();
$items = array();
$c_aid = dbRes($result, 0, "userid");
$c_nm1 = dbRes($result, 0, "name1");
$c_nm2 = dbRes($result, 0, "name2");
$c_1ad = dbRes($result, 0, "address1");
$c_2ad = dbRes($result, 0, "address2");
$c_zsc = dbRes($result, 0, "state_zip");
$c_tat = dbRes($result, 0, "active");
$c_vid = dbRes($result, 0, "division");
$c_dio = $newOrderID;
$c_pyt = dbRes($result, 0, "price_type");
$cust->setVar($c_aid, $ACCTNUMBER);
$cust->setVar($c_nm1, $ACCTNAME);
$cust->setVar($c_nm2, $ACCTNAME2);
$cust->setVar($c_1ad, $ACCTADDRESS);
$cust->setVar($c_2ad, $ACCTADDRESS2);
$cust->setVar($c_zsc, $ACCTSTATEZIP);
$cust->setVar($c_tat, $ACCTACTIVE);
$cust->setVar($c_vid, $ACCTDIVISION);
$cust->setVar($c_dio, $ORDERID);
$cust->setVar($c_pyt, $ACCTTYPE);
$_SESSION["cust"] = $cust;
$_SESSION["basket"] = $basket;
$_SESSION["items"] = $items;
$_SESSION["custItems"] = $custItems;
} // end if $found
} // end if $status
session_write_close();
?>
<?php
/*******************************************************************************/
/* File: get_vars.php Usage: include ('get_vars.php'); */
/* Author: Nyle E. Davis Create Date: 11/04/08 */
/* Mod by: Nyle E. Davis Mod Date: 12/02/08 */
/* Purpose: Get the registered Class and Session variables and their values. */
/*******************************************************************************/
/* Mod History: 12/02/08 */
/* Attempt to correct problem with 'session_start();' errors. */
/*******************************************************************************/
// session_start();
if (!class_exists('customer')) include 'classes.inc.php';
if (class_exists('customer')) {
$cust = new customer();
$c_cid = $cust->getVar($ACCTNUMBER);
$c_div = $cust->getVar($ACCTDIVISION);
$c_nam = $cust->getVar($ACCTNAME);
$c_nm2 = $cust->getVar($ACCTNAME2);
$c_ad1 = $cust->getVar($ACCTADDRESS);
$c_ad2 = $cust->getVar($ACCTADDRESS2);
$c_csz = $cust->getVar($ACCTSTATEZIP);
$c_typ = $cust->getVar($ACCTTYPE);
$c_oid = $cust->getVar($ORDERID);
}
if (!$cust->getVar($ACCTNUMBER)) {
$cust = $_SESSION['cust'];
foreach ($cust as $key => $val) {
// echo "K=> $key V=> $val <br>";
switch($key) {
case 'acctNumber':
$c_cid = $val;
break;
case 'acctDivision':
$c_div = $val;
break;
case 'acctName':
$c_nm1 = $val;
break;
case 'acctName2':
$c_nm2 = $val;
break;
case 'acctAddress':
$c_ad1 = $val;
break;
case 'acctAddress2':
$c_ad2 = $val;
break;
case 'acctStateZip':
$c_csz = $val;
break;
case 'acctType':
$c_typ = $val;
break;
case 'orderID':
$c_oid = $val;
break;
} // end switch
} // end foreach
} // end if !$cust
$cust_inf = array('acctNumber'=>$c_cid,'acctDivision'=>$c_div,'acctName'=>$c_nm1,
'acctName2'=>$c_nm2,'acctAddress'=>$c_ad1,'acctAddress2'=>$c_ad2,
'acctStateZip'=>$c_csz,'acctType'=>$c_typ,'orderID'=>$c_oid);
$_SESSION['$cust_inf'] = $cust_inf;
if (class_exists('login')) {
$log = new login();
$l_uid = $log->getVar($LOGID);
$l_pwd = $log->getVar($LOGPD);
$l_sta = $log->getVar($LOGST);
$l_ses = $log->getVar($LOGSES);
}
if (!$log->getVar($LOGID)) {
$log = $_SESSION['log'];
foreach ($log as $key => $val) {
// echo "K=> $key V=> $val <br>";
switch($key) {
case 'log_id':
$l_uid = $val;
break;
case 'log_pd':
$l_pwd = $val;
break;
case 'log_status':
$l_sta = $val;
break;
case 'log_session':
$l_ses = $val;
break;
} // end switch
} // end foreach
}
$log_inf = array('log_id'=>$l_uid,'log_pd'=>$l_pwd,'log_status'=>$l_sta,
'log_session'=>$l_ses);
$_SESSION['$log_inf'] = $log_inf;
session_write_close();
include 'reg_vars.php';
?>
I'm developing on Windows box running WAMP, but host test site on Ubuntu 7.10 server. Production environment is RHE4, so have to ensure PHP4 compatibility.
Code works fine on dev box, but get the errors:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/test/html/reg_vars.php:15) in /var/www/test/html/reg_vars.php on line 9
when running on test box.
I put in session test (lines 17-19) to attempt making sure the session only opens once if (!session_is_registered ($sesNameID)) {
session_start(); // Moved here 11/24/08 to avoid load issues.
}
but still get the errors. I even changed all my 'include ()' statements for these files to 'include_once()'.
I have to call the reg_vars and get_vars routines several times as my shopping cart is housed in an IFRAME and vars do not pass well without these being re-called. I had to add the 'session_write_close();' commands to each file, as the IFRAME would not work without them.
Not sure what to look for next. Wondering what I need to add/edit to fix this? Would changing my 'include()' statements to 'require()' statement resolve this since there is less error checking?
Will appreciate all your help.
Thanks!
OMR