Hey everyone,
I get: Fatal error: Cannot redeclare ftok() on line 66
I cannot seem to find where it redeclares ftok(). Any help would be appreciated.
<?php
// remove unwanted stuff from user input
function clean($input, $sep = 0) {
$sp = strpos($input, $sep);
// only look for separator if really needed
$input = (!empty($sep) && ($sp !== false)) ? substr($input, 0, $sp) : $input;
$input = str_replace("\\", "/", strip_tags($input));
$input = str_replace("$", "$", htmlspecialchars($input, ENT_QUOTES));
// Limit the maximum length to 1024 chars
return trim(substr($input, 0, 1024));
}
// generates string output of an array
function array_to_str($tab) {
static $indent = "";
$oldindent = $indent;
$indent .= " ";
$sep = "";
$str = $indent."array(\n";
$last_is_array = false;
$k = 0;
reset($tab);
while (list($key, $val) = each($tab)) {
// The separator treatment
if (($last_is_array) || (is_array($val) && ($k !== 0))) {
$str .= $sep."\n";
}
else $str .= $sep;
// The key treatment
if (preg_match("%^[\d]+$%", $key)) {
if ($key !== $k) {
$str .= (((is_array($val)) || ($k === 0) || ($last_is_array)) ? "$indent " : "")
."$key =>".((is_array($val)) ? "\n" : " ");
}
else $str .= ($k === 0) ? (is_array($val) ? "" : "$indent ") : "";
}
else {
$str .= (((is_array($val)) || ($k === 0) || ($last_is_array)) ? "$indent " : "")
."\"$key\" =>".((is_array($val)) ? "\n" : " ");
}
// The value treatment
$last_is_array = false;
if (is_array($val)) {
$str .= array_to_str($val);
$last_is_array = true;
$sep = ",";
}
else {
$str .= (preg_match("%^[\d]+$%", $val) ? $val : "\"$val\"");
$sep = ", ";
}
$k++;
}
$str .= "\n$indent)";
$indent = $oldindent;
return $str;
}
// ftok emulation for sem_get
function ftok($file) {
$stat = stat($file);
$dev = decbin($stat[0]);
$inode = decbin($stat[1]);
foreach (array("dev", "inode") as $what) {
$lim = ($what == "inode") ? 16 : 8;
if ($$what == $lim) continue;
elseif ($$what < $lim) $$what = str_pad($$what, $lim, 0);
else $$what = substr($$what, -$lim);
}
return bindec("1111000".$dev.$inode);
}
// returns the lock id
function semlock($file) {
if (!$id = sem_get(ftok($file), 1) || !sem_acquire($id)) {
if (is_resource($id)) {
sem_release($id);
@sem_remove($id);
}
return false;
}
return $id;
}
// write data, returns file pointer on success else false
function get_lock($file, $append = false) {
$mode = !$append ? (defined("_DIO") ? O_RDWR : "rb+") : (defined("_DIO") ? O_WRONLY : "ab");
$fp = defined("_DIO") ? dio_open($file, $mode | O_APPEND) : fopen($file, $mode);
if (!is_resource($fp)) return false;
if (defined("_SEM") && ($id = semlock($file))) return array($fp, $id);
if (defined("_DIO") && (dio_fcntl($fp, F_SETLK, 1) !== -1)) return $fp;
if (defined("_FLK") && flock($fp, LOCK_EX)) return $fp;
defined("_DIO") ? dio_close($fp) : fclose($fp);
return false;
}
// writes data or truncates file and returns file pointer on success
function write_data($fp, $data = false, $append = false) {
if (defined("_SEM") && is_array($fp)) list($fp, $id) = $fp;
if (!is_resource($fp)) return false;
if (defined("_DIO")) {
$append ? "" : dio_truncate($fp, 0);
$data ? dio_write($fp, $data) : "";
dio_fcntl($fp, F_SETLK, 0);
dio_close($fp);
return true;
}
set_file_buffer($fp, 0);
$append ? "" : ftruncate($fp, 0);
$data ? fwrite($fp, $data) : "";
defined("_FLK") ? flock($fp, LOCK_UN) : "";
if (defined("_SEM") && is_resource($id)) {
sem_release($id);
@sem_remove($id);
}
return fclose($fp);
}
//initialise the marker class
function exec_marker() {
$marker =& new marker;
if ($marker->ignored === true) return msg(false, "i");
else $msg =& $marker->write_entry();
switch ($msg[1]) {
case "o":
if (!defined("_OK")) define("_OK", 1);
return msg($msg[0], "o");
case "l":
return msg($msg[0], "l");
case "w":
return msg($msg[0], "w");
default:
return msg($msg[0]);
}
}
// kill stats if desired
function kill_stats() {
global $ACCESS_FILE, $CACHE_PATH, $COUNTER_FILES, $COUNTER_PREFIX, $COUNTER_SUFFIX,
$LAST_FILE;
$paths = array($ACCESS_FILE, $LAST_FILE);
for ($i = 0; $i < $COUNTER_FILES; $i++) $paths[] = $CACHE_PATH.$COUNTER_PREFIX.$i.$COUNTER_SUFFIX;
foreach ($paths as $file) fclose(fopen($file, "wb"));
return true;
}
// Parse all counter files of var/ and return an array of N rows,
// with N as amount of new connections, sorted in increasing time of connection.
// The counters files are emptied afterwards.
function counter_to_array() {
global $CACHE_PATH, $COUNTER_PREFIX, $COUNTER_SUFFIX, $SEP, $COUNTER_COLUMNS,
$COUNTER_COLUMN_NAMES, $COUNTER_FILES, $DEBUG;
for ($i = 0, $new_cnt = 0; $i < $COUNTER_FILES; $i++) {
$file = $CACHE_PATH.$COUNTER_PREFIX.$i.$COUNTER_SUFFIX;
if (!is_readable($file)) {
if (!empty($DEBUG)) print(msg($file));
$no_acc = 1;
continue;
}
if (!is_writable($file) && empty($no_acc)) {
if (!empty($DEBUG)) print(msg($file, "w"));
continue;
}
for ($j = 0, $data = file($file), $max = count($data); $j < $max; $j++) {
$line = explode($SEP, trim($data[$j]));
if (empty($line[0]) || !preg_match("%[\d]+%", $line[0])) continue;
for ($k = 0; ($k < $COUNTER_COLUMNS); $k++) {
$new_visits[$new_cnt][($COUNTER_COLUMN_NAMES[$k])] = trim($line[$k]);
}
$new_cnt++;
}
// reset the counter files
fclose(fopen($file, "wb"));
}
if (!empty($new_visits)) usort($new_visits, "sort_time_sc");
return (empty($new_visits) ? array() : $new_visits);
}
?>
Line 66 to line 79:
function ftok($file) {
$stat = stat($file);
$dev = decbin($stat[0]);
$inode = decbin($stat[1]);
foreach (array("dev", "inode") as $what) {
$lim = ($what == "inode") ? 16 : 8;
if ($$what == $lim) continue;
elseif ($$what < $lim) $$what = str_pad($$what, $lim, 0);
else $$what = substr($$what, -$lim);
}
return bindec("1111000".$dev.$inode);
}