|
|
|
<?
// ------------------------------------------------------------------
// PHP Session Management Functions
// ------------------------------------------------------------------
// Author: Mark Henderson (mark@togglemedia.com)
// Version: 0.01 (alpha)
// Disclaimer: Use of this code at your own risk
//
// These two functions read and write the contents of a
// multi-dimesional array, $session, to a file with a file name
// $session_id, stored in a directory $session_path.
//
// This is useful for applications wishing to keep state, where a
// "session id" is passed from page to page using either a cookie
// or a variable embeded in all URL's.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// READ SESSION
// ------------------------------------------------------------------
Function read_session() {
global $session, $session_path, $session_id;
/* set up session variables */
/* What should we do if the script cannot find the session file? */
$fp = fopen( $session_path.$session_id, "r" );
while(!feof($fp))
{
$line = fgets($fp,100);
$tok = strtok($line, "=");
$a = $tok;
$tok = strtok( "=");
$b = chop($tok);
$c = UrlDecode($b);
if((strlen($c) > 0) && (strlen($a) > 0))
{
eval( "\$session$a = \$c;");
}
}
fclose($fp);
return($fp);
}
// ------------------------------------------------------------------
// WRITE SESSION
// ------------------------------------------------------------------
Function write_session() {
global $session_path, $session_id, $session, $sm_string_array;
$level = 0;
unset($sm_string_array);
reset($session);
/* Write array to session file */
$fp = fopen($session_path . $session_id, "w");
if($fp != "false")
{
write_session_loop($fp);
} else {
echo "<h2>Session Error " . $fp . ": Cannot Write to File!</h2><br>\n";
}
fclose($fp);
}
Function write_session_loop($fp) {
global $session, $sm_string_array;
static $level=0;
if(IsSet($sm_string_array))
{
$num_elements_string_array = count($sm_string_array);
} else {
$num_elements_string_array = 0;
}
if($num_elements_string_array > 0)
{
$s=0;
$string = "";
while(($s < $num_elements_string_array) && IsSet($sm_string_array[$s]))
{
if(gettype($sm_string_array[$s]) == "string")
{
$string = $string . "['" . $sm_string_array[$s] . "']";
} else {
$string = $string . "[" . $sm_string_array[$s] . "]";
}
$s++;
}
} else {
$string= "";
}
eval( "\$test_array= \$session$string;");
if(gettype($test_array) == "array")
{
$num_elements = count($test_array);
} else {
$num_elements = 0;
eval( "\$value = \$session$string;");
$value_url = UrlEncode($value);
$pair = $string . "=" . $value_url;
fputs($fp, "$pair\n");
}
eval( "reset(\$session$string);");
$x=0;
while($x < $num_elements)
{
eval( "\$key = key(\$session$string);");
$sm_string_array[$level] = $key;
$level++;
unset($sm_string_array[$level]);
write_session_loop($fp); // loop recursively!!!
$level--;
eval( "next(\$session$string);");
$x++;
}
}
?> |
|
| Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms | | | Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | A very simple and efficient split bar the B-Z bar , for mysql and php ...
Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms | | | PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP, Algorithms, Security, Authentication, Encryption | | | IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival. Categories : PHP, Algorithms, Security, URLs | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math. | | | Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers. Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | |
|
|
|