Version: 0.2
Type: Function
Category: Other
License: GNU General Public License
Description: This function takes the string data from session_encode() and returns the variable names, for that session, in an array.
//################################################################## // Function: session_var_names() // Version: 0.2 // Programmer: Dannie M Stanley <[email protected]> // Company: SpinWeb Net Designs, Inc. <http://www.spinweb.net/> // Description: This function takes the string data from session_encode() // and returns the variable names for that session in an // array. // Takes: encoded string // Returns: array containing variable names // Date: 08/24/2000 // License: Public // Notes: Please send updates/fixes. Thanks and have a good day! //################################################################## // ChangeLog: 0.2 Added support for null variables //################################################################## function session_var_names($enc_data) { // It seems when there is an array it may contain | or ; between { and } // so here I effectively delete all data between { and } and set } = ; // so when I parse later it knows where the variable data ended. while(strpos($enc_data, "{")) { $decode_data .= substr($enc_data,0,strpos($enc_data, "{")); $decode_data .= strstr($enc_data,"}"); $decode_data = str_replace("}", ";", $decode_data); $enc_data = $decode_data; } // Move all variable names and their data into array elements $format_data = explode(";", $enc_data); // Snatch the variable name (first part of string before |) for($i=0; $i<count($format_data); $i++) { // If the variable is null it is set to !varname so // this grabs the first one and all subsequent null vars if(substr($format_data[$i], 0, 1) == "!") { $bang_vars = $format_data[$i]; while(strstr($bang_vars, "!")) { $names[] = substr($bang_vars, 1, strpos($bang_vars, "|")-1); $bang_vars = strstr($bang_vars,"|"); } } else { $var_name = substr($format_data[$i], 0, strpos($format_data[$i], "|")); $names[] = $var_name; } } // Delete last entry if empty if($names[count($names)-1] == "") array_pop($names); return $names; }