'; } } function get_visits($id, $file){ if(!file_exists($file)){ $visits[date('Ymd')][$id] = 0; $visits['nocount'] = 0; $visits['ans'] = Array(); return $visits; } if(is_readable($file)){ $handle = fopen($file, 'r'); $contents = fread($handle, filesize($file)); fclose($handle); $visits = unserialize($contents); return $visits; } else { echo ""; return null; } } function set_visits($visits, $file){ if(is_writable($file) or (is_writable(dirname($file)) and !file_exists($file))){ $handle = fopen($file, 'w'); if (!fwrite($handle, serialize($visits))) { echo ""; } fclose($handle); } else { echo ""; } } function get_salt($hashfile){ // a) file does not exist yet if(!file_exists($hashfile)){ if(is_writable(dirname($hashfile))){ $hash[0] = date('Ymd'); $hash[1] = mt_rand(); $handle = fopen($hashfile, 'w'); if (!fwrite($handle, serialize($hash))) { echo ""; } fclose($handle); } else { echo ""; } } if(is_readable($hashfile)){ $handle = fopen($hashfile, 'r'); $contents = fread($handle, filesize($hashfile)); fclose($handle); $hash = unserialize($contents); // b) hash is not of today if($hash[0] != date('Ymd')){ $hash[0] = date('Ymd'); $hash[1] = mt_rand(); $handle = fopen($hashfile, 'w'); if (!fwrite($handle, serialize($hash))) { echo ""; } fclose($handle); } return $hash[1]; } else { echo ""; return 1; } } function load_var($file){ if(!file_exists($file)){ return null; } if(is_readable($file)){ $handle = fopen($file, 'r'); $contents = fread($handle, filesize($file)); fclose($handle); $var = unserialize($contents); return $var; } else { echo ""; return null; } } function save_var($file, $var){ if(is_writable($file) or (is_writable(dirname($file)) and !file_exists($file))){ $handle = fopen($file, 'w'); if (!fwrite($handle, serialize($var))) { echo ""; } fclose($handle); } else { echo ""; } } ?>