<?
// ------------------------------------------------------------------
// 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 Execute a command to a string Categories : PHP , Program Execution , Filesystem Fetching product details from the commission junction website using php Categories : PHP , FTP , Filesystem , Compression Single-file PHP news system with automatic folder structure creation Categories : PHP , Filesystem , Arrays Calculate the great circle distance between two latitude/longitudes
Categories : Algorithms , PHP A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database. Categories : PHP , Filesystem , FTP , Date Time , Databases 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 Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP , PHP , HTML , PDF , Excel Read DPI value from image with PHP Categories : PHP , Graphics , Filesystem getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory,
filtered by regular expression and either sorted or randomized. Good for
random pictures and graphics. Categories : PHP , Filesystem , Directories Grab images from one or more URLs and save them to a specified local directory. Categories : PHP , Filesystem , Strings , Arrays Listing the 10 most recently updated files in a given dir by using last-
modified variable and printing to html with link to the file Categories : PHP , Directories , Filesystem The toll booth Categories : PHP , Java Script , Filesystem SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge
response login algorithms over an insecure connection. Categories : Algorithms , PHP , Security