function loginstatus() { $filename = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); include 'config/config.php'; //全局设置 if (!isset($_POST['FC_USER'])) { if ($filename != "login.php") { echo '<SCRIPT>window.location.href="login.php"</SCRIPT>'; } loginfo(1); return 1; exit; } else { if ($_POST['FC_USER'] != $loginuser || $_POST['FC_PW'] != $loginpasswd) { if ($filename != "login.php") { echo '<SCRIPT>window.location.href="login.php"</SCRIPT>'; } loginfo(2); return 2; exit; } else { if ($_POST['FC_USER'] == $loginuser && $_POST['FC_PW'] == $loginpasswd || $_SESSION['FC_GOODJOU'] == "jou") { $_SESSION['FC_GOODJOU'] = "jou"; passthru('echo "' . $passkey . '" >> /dev/ttyS1'); if ($filename == "login.php") { echo '<SCRIPT>window.top.location.href="../index.php"</SCRIPT>'; } return 0; } else { if ($filename != "login.php") { echo '<SCRIPT>window.location.href="login.php"</SCRIPT>'; } loginfo(3); return 3; exit; } } } }
/** * 插入数据 * @param $sql * @return unknown_type */ function sql_insert($sql) { $stime = my_microtime_float(); sql_query($sql); loginfo($stime, $sql); return sql_fetch_one_cell('select last_insert_id()'); }
function replyTweet($tweet, $message) { global $testing; global $twit; $message = "@" . $tweet->user->screen_name . " " . $message; $replytoid = $tweet->id_str; loginfo("Replied to " . $replytoid . " with " . $message . $testing); if (!$testing) { $twit->post('statuses/update', array('status' => $message, 'in_reply_to_status_id' => $replytoid)); } }
<?php function logMessage($loglevel, $message) { date_default_timezone_set('America/Chicago'); $date = date('Y-m-d'); $handle = fopen("{$date}.log", 'a'); $content = trim(fwrite($handle, date('Y-m-d h:i:s A T') . " " . $loglevel . " " . $message . PHP_EOL)); fclose($handle); return $content . PHP_EOL; } function loginfo() { logMessage("[INFO]", "Get up off'a dat thang!"); } function logerror() { logMessage("[ERROR]", "Err time gon' doit!"); } loginfo(); logerror();
/** * 插入数据 返回是否成功 * @param $sql * @param $host * @param $user * @param $PWD * @param $name * @param $key * @param $port */ function sql_insertNoCellDyn($sql, $host, $user, $PWD, $name, $key, $port) { $link = get_connectDyn($host, $user, $PWD, $name, $key, $port); if (!$link) { throw new Exception(mysqli_connect_errno()); } $r = $link->query($sql); $stime = my_microtime_floatDyn(); loginfo($stime, $sql); return $r; }
/** * Deletes a directory recursively, no matter whether it is empty or not */ function deltree($dir, $deleteParent = false) { if (!file_exists($dir)) { return false; } if (!is_dir($dir) || is_link($dir)) { return unlink($dir); } // prevent deletion of current directory $cdir = realpath($dir); $adir = dirname(__FILE__); $cdir = $cdir . (substr($cdir, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR); $adir = $adir . (substr($adir, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR); if ($cdir == $adir) { loginfo(" * Contents of '" . basename($adir) . "' folder will not be cleaned up.\n"); return true; } // process contents of this dir $files = array_diff(scandir($dir), array('.', '..')); $sep = substr($dir, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR; foreach ($files as $file) { is_dir("{$dir}{$sep}{$file}") ? deltree("{$dir}{$sep}{$file}", true) : unlink("{$dir}{$sep}{$file}"); } if ($deleteParent) { return rmdir($dir); } else { return true; } }