hi guys thanks for all your help last time, maybe somebody out there has some ideas for this little snag also.
I'm using "custom session handlers" tied into the php api via the session_set_save_handler() function and its throwing both "cannot send cookie" and "cannot send cache limiter" errors - BUT it is still writing a generated SID, the expiration, and my input var(s) to the databae on execution so I was wondring if anywone knew what the problem was and or how to go about correcting it?
errors and code below:
error1
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Program Files\Apache Group\Apache2\htdocs\oldcool\login.php:11) in F:\Program Files\Apache Group\Apache2\htdocs\oldcool\login.php on line 24
error2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\Apache Group\Apache2\htdocs\oldcool\login.php:11) in F:\Program Files\Apache Group\Apache2\htdocs\oldcool\login.php on line 24
handlers
note - this code is almost coppied verbatim from the book
<?php
/////////////////////////////////////////////////////////////////////////////
//SIX FUNCTIONS TO ACT AS ARGUMENTS FOR THE session_set_save_handler()///////
//FUNCTION --> ONE TO "open" THE SESSION, ONE TO "close" THE SESSION, ONE////
//TO "read", ONE TO "write", ONE TO "destroy", AND ONE TO "collect session///
//garbage".//////////////////////////////////////////////////////////////////
function open_session(){
//open connection to mysql db -->use mysql_pconnect() function
mysql_pconnect("hostname","username","password")or die("Connection cannot be made");
mysql_select_db("dbname")or die("Cannot find requested data base");
}
function close_session(){
//mysql_pconnect does not have to be closed but this does need to be a defined function for session_set_save_handler() function
return 1;
}
function read_session($SID){
//mysql SELECT for the VALUE (session data) of a particular record
$select_sess="SELECT VALUE FROM SESSIONS WHERE SID = '$SID' AND EXPIRATION > ".time().";";
$sess_trans=mysql_query($select_sess);
if(mysql_num_rows($sess_trans)){
$row=mysql_fetch_array($sess_trans, MYSQL_ASSOC);
$value=$row['VALUE'];
return $value;
}else{
return " ";
}
}
function write_session($SID,$value){
//INSERT new values into db || append new values to preexisting values?
$lifetime=get_cfg_var("session.gc_maxlifetime");
$expiration=time()+$lifetime;
$insert_sess="INSERT INTO SESSIONS (SID, EXPIRATION, VALUE) VALUES ('$SID', '$expiration', '$value');";
$sess_trans=mysql_query($insert_sess);
if(!$sess_trans){
$update_sess="UPDATE SESSIONS SET EXPIRATION = '$expiration', VALUE = '$value' WHERE SID = '$SID' AND EXPIRATION >".time().";";
$sess_trans=mysql_query($update_sess);
}
}
function destroy_session($SID){
//DELETE particular record with appropriate SID
$delete_sess="DELETE FROM SESSIONS WHERE SID = '$SID';";
$sess_trans=mysql_query($delete_sess);
}
function garbage_session($lifetime){
//DELETE all sessions that have past expiration
$garbage_sess="DELETE FROM SESSIONS WHERE EXPIRATION < ".time()-$lifetime.";";
$sess_trans=mysql_query($garbage_sess);
return mysql_affected_rows($sess_trans);
}
session_set_save_handler("open_session","close_session","read_session","write_session","destroy_session","garbage_session");
?>
code where included code above is called with line numbers referenced by error msgs
11<?php
- require('session_library.php');
24 session_start();
- $_SESSION['UNAME']=$_POST['UNAME'];