Page 1 of 1

Why session data is empty?

Posted: Tue May 23, 2006 7:14 am
by bleed
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Phpbb sessions in my scripts

Code: Select all

function sess_mysql_read($sess_id) 
{ 
// read userdata from database and store it to $output 

    ... 

    return($output); 
} 

function sess_mysql_write($sess_id, $val) 
{ 
//!! $val is empty if isset($_COOKIE['phpbb2mysql_sid']) Why??? !!!!! 
//receive $val, parse it and store to database

... 

    return(true);     
} 

  session_set_save_handler("sess_mysql_open", "", "sess_mysql_read", "sess_mysql_write", "sess_mysql_destroy", "sess_mysql_gc"); 
  session_name("sid");     

// if phpbb started session use phpbb session_id if else use our session_id
  if(isset($_COOKIE['phpbb2mysql_sid'])) 
      { 
       session_id($_COOKIE['phpbb2mysql_sid']); 
      } 

  session_start(); 

  $_SESSION['test'] = "ok"; 

  echo $_SESSION['test'];
If user not logged to phpbb, $_COOKIE['phpbb2mysql_sid'] is empty

function sess_mysql_write receive $val
$val == 'test|s:2:"ok";'
Write to database session param 'test'

and script print
--------------------------------------------------------------------------------
ok
--------------------------------------------------------------------------------


If user login in phpbb
function sess_mysql_read
read userdata in $_SESION
function sess_mysql_write receive $val
$val == "" and store in database "null"
and script print:
--------------------------------------------------------------------------------
ok
--------------------------------------------------------------------------------
but(!!!) sess_mysql_write $val == "", $val is emty why???

Why function sess_mysql_write receive empty $val help my please!

PHP version 4.3.9


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 23, 2006 7:50 am
by xpgeek
show full php code please...

Posted: Tue May 23, 2006 8:17 am
by bleed
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

function sess_mysql_write($sess_id, $val)
{
// write log
   $sess_file = "test2write";
   if ($fp = fopen($sess_file, "a")) 
    {
     fwrite($fp, "in: ".serialize($val)."\n");
    }

 // TODO
}

function sess_mysql_read($sess_id)
{
    // Select the data belonging to session $sess_id from the MySQL phpBB session table    
    $result = mysql_query("SELECT * FROM ".SESSIONS_TABLE." WHERE session_id = '$sess_id'") or die(mysql_error());

    // Return an empty string if no data was found for this session
    if(mysql_num_rows($result) == 0)
    {
        return("");
    }

    // Session data was found, so fetch and return it
    $row = mysql_fetch_array($result);

// encode data to php session transfer format, 
    $val = $row['data'];

    $data = explode(";", $val);
    $sessdata = array();
 
    for($i=0;$i<count($data);$i++)
    {
     list ($key, $val) = explode("|",$data[$i].";");
     if(!empty($val))
     {
      $sessdata[$key]=unserialize($val);
     }
    }

    foreach($row as $k=>$v)
    {
     if(!array_key_exists($k, $sessdata))
     {
      $sessdata[$k] = $v;
     }
    }

    $output = array();

    foreach($sessdata as $k=>$v)
    {
     $output[] = implode("|", array($k, serialize($v))); 
    }

    $output = implode("", $output);

    mysql_free_result($result);

//read log
  $sess_file = "test2write";
  if ($fp = fopen($sess_file, "a")) 
  {
   fwrite($fp, "out: ".$output."\n");
  }

    return($output);
}

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]