The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Flatbase
Posted by: Kisom | February 11, 2007 @ 6:41am
PHP Code
[
Download
]
<?php /* >Copyright 2007 Kisom Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. >Contact: h at (nospam) ck3r dot org */ function fb_test() { $__random_name = rand(); while (file_exists($__random_name)) { $__random_name = rand().time(); } $handle = fopen($__random_name, "w"); $__data_value = rand(); fwrite($handle, $__data_value); fclose($handle); if (file_get_contents($__random_name) != $__data_value) { unlink($__random_name); return false; } unlink($__random_name); if (file_exists($__random_name)) { return false; } return true; } function fb_static($__data, $__array) { if (!in_array($__data, $__array)) { die("<b>FlatBase Error: fb_static, value <u>".htmlentities($__data)."</u> cannot be used.</b>"); } } function fb_array_swap($array, $swap1, $swap2) { if (!is_array($array)) { die("<b>FlatBase Error: fb_array_swap, invalid type given (expected array).</b>"); } if (!isset($swap1) || !isset($swap2)) { die("<b>FlatBase Error: fb_array_swap, no keys given.</b>"); } if (!isset($array[$swap1]) || !isset($array[$swap2])) { die("<b>FlatBase Error: fb_array_swap, keys do not exist.</b>"); } $__temp = $array[$swap1]; $array[$swap1] = $array[$swap2]; $array[$swap2] = $__temp; return $array; } function fb_a2s($Array) { $__return_value = ''; $__null_value = "^^^"; foreach ($Array as $Key => $__current_value) { if (is_array($__current_value)) { $__return_value='^^array^'.fb_a2s($__current_value); } else { $__return_value = (strlen($__current_value)>0)?$__current_value:$__null_value; } $__return_value .= urlencode(base64_encode($Key)) . '|' . urlencode(base64_encode($__return_value)).'||'; } return urlencode(substr($__return_value,0,-2)); } function fb_s2a($__string_value) { $__return_value = array(); $__string_value = urldecode($__string_value); $TempArray = explode('||',$__string_value); $__null_value = urlencode(base64_encode("^^^")); foreach ($TempArray as $__tmp_value) { list($Key, $__current_value) = explode('|', $__tmp_value); $DecodedKey = base64_decode(urldecode($Key)); if ($__current_value != $__null_value) { $__return_value = base64_decode(urldecode($__current_value)); if(substr($__return_value,0,8) == '^^array^') { $__return_value=fb_s2a(substr($__return_value,8)); } $__return_value[$DecodedKey] = $__return_value; } else $__return_value[$DecodedKey] = NULL; } return $__return_value; } function fb_read($__value_db) { if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); $__errors = 0; while (empty($__content)) { if ($__errors == 100) { die("<b>FlatBase Error: Access error in database ".$__value_db."</b>"); } $__errors++; $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); usleep(100000); } if ($__content == "@EMPTY") { return(""); } else { return base64_decode($__content); } } else { die("<b>FlatBase Error: Unable to read database ".$__value_db."</b>"); } } function fb_name($__value_db) { return sha1($__value_db).md5($__value_db).".secure.fba"; } function fb_array_read($__value_db) { if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); $__errors = 0; while (empty($__content)) { if ($__errors == 100) { die("<b>FlatBase Error: Access error in database ".$__value_db."</b>"); } $__errors++; $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); usleep(100000); } if ($__content == "@EMPTY_ARRAY") { return array(); } else { $__return = fb_s2a(base64_decode($__content)); if (is_array($__return)) { return $__return; } else { die("<b>FlatBase Error: Database ".$__value_db." is corrupt</b>"); } } } else { die("<b>FlatBase Error: Unable to read database ".$__value_db."</b>"); } } function fb_boolean_read($__value_db) { if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); $__errors = 0; while (empty($__content)) { if ($__errors == 100) { die("<b>FlatBase Error: Access error in database ".$__value_db."</b>"); } $__errors++; $__content = file_get_contents(sha1($__value_db).md5($__value_db).".secure.fba"); usleep(100000); } if ($__content == 1) { return true; } elseif ($__content == 2) { return false; } else { die("<b>FlatBase Error: database ".$__value_db." is corrupt</b>"); } } else { die("<b>FlatBase Error: Unable to read boolean from ".$__value_db."</b>"); } } function fb_exists($__value_db) { if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { return false; } } function fb_drop($__value_db) { if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { unlink(sha1($__value_db).md5($__value_db).".secure.fba"); if (!file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { $errors = 0; while(file_exists(sha1($__value_db).md5($__value_db).".secure.fba") && $errors != 100) { unlink(sha1($__value_db).md5($__value_db).".secure.fba"); if (!file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { $errors++; sleep(1); if ($errors == 10) { die("<b>FlatBase Error: Unable to drop database ".$__value_db."</b>"); } } } } } else { return false; } } function fb_write($__value_db, $__value_content) { $__database_handle = fopen(sha1($__value_db).md5($__value_db).".secure.fba", "w"); if (!flock($__database_handle, LOCK_EX)) { die("<b>FlatBase Error: Unable to get exclusive lock on database ".$__value_db."</b>"); } if (empty($__value_content)) { $__value_content = "@EMPTY"; } else { $__value_content = base64_encode($__value_content); } fwrite($__database_handle, $__value_content); fclose($__database_handle); if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { die("<b>FlatBase Error: Unable to change database ".$__value_db."</b>"); } } function fb_array_write($__value_db, $__value_content) { if (!is_array($__value_content)) { die("<b>FlatBase Error: Wrong datatype in ".$__value_db.". Expected array.</b>"); } $__database_handle = fopen(sha1($__value_db).md5($__value_db).".secure.fba", "w"); if (!flock($__database_handle, LOCK_EX)) { die("<b>FlatBase Error: Unable to get exclusive lock on database ".$__value_db."</b>"); } $__this_save = base64_encode(fb_a2s($__value_content)); if (empty($__this_save)) { $__this_save = "@EMPTY_ARRAY"; } fwrite($__database_handle, $__this_save); fclose($__database_handle); if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { die("<b>FlatBase Error: Unable to change database array ".$__value_db."</b>"); } } function fb_boolean_write($__value_db, $__value_content) { if (!is_bool($__value_content)) { die("<b>FlatBase Error: Wrong datatype in ".$__value_db.". Expected boolean.</b>"); } $__database_handle = fopen(sha1($__value_db).md5($__value_db).".secure.fba", "w"); if (!flock($__database_handle, LOCK_EX)) { die("<b>FlatBase Error: Unable to get exclusive lock on database ".$__value_db."</b>"); } if ($__value_content) { $__value_content = 1; } else { $__value_content = 2; } fwrite($__database_handle, $__value_content); fclose($__database_handle); if (file_exists(sha1($__value_db).md5($__value_db).".secure.fba")) { return true; } else { die("<b>FlatBase Error: Unable to change database boolean ".$__value_db."</b>"); } } ?>
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.61 / 8
417 Votes