3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Hurricane Control Panel © 2014, a web control panel by Hurricane Development of http://www.HurricaneDevelopment.com is licenced under a Creative Commons Attribution-NoDerivatives 4.0 International License Permissions beyond the scope of this licence may be available at http://creativecommons.org/licenses/by-nd/4.0/ */ defined("_HEXEC") or die("This file may not be accessed directly"); class VARS { public static $errors = false; public static $extraJS = false; public static $scriptJS = false; public static $extraCSS = false; } abstract class GeneralUTIL { /** * Error functions * */ public static function addErr($err) { VARS::$errors[] = $err; } public static function logger($content, $level = LOGGER_INFO) { if (!file_exists("logs")) { mkdir("logs"); } $scanned_directory = array_diff(scandir("logs", SCANDIR_SORT_DESCENDING), array('..', '.')); $logs = false; if (sizeof($scanned_directory) == 0) { file_put_contents("logs/log.1", "", LOCK_EX); chmod("logs/log.1", 0600); $logid = 1; } else { foreach ($scanned_directory as $key => $value) { if (strpos($value, "log.") !== false) { $logs[] = $value; } } $logid = explode(".", $logs[0]); $logid = $logid[1]; if (filesize("logs/log." . $logid) >= 200000) { $logid = ((int) $logid) + 1; file_put_contents("logs/log." . $logid, "", LOCK_EX); chmod("logs/log." . $logid, 0600); } } date_default_timezone_set("America/New_York"); $d = getdate(); file_put_contents("logs/log." . $logid, "{$d['mon']}/{$d['mday']}/{$d['year']} {$d['hours']}:{$d['minutes']}:{$d['seconds']} $level $content \n", FILE_APPEND | LOCK_EX); } public static function sha512($password, $salt = null) { if ($salt == null) { $cost = 50000; $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); $salt = sprintf('$6$rounds=%d$', $cost) . $salt; } return crypt($password, $salt); } public static function matchSha512($password, $hash) { if (crypt($password, $hash) === $hash) { return true; } return false; } } class PluginUTIL extends GeneralUTIL { public static function addJS($jsPath) { $debugArray = debug_backtrace(); $pluginAlias = UTIL::getBetween($debugArray[0]['file'], "/plugins/plugin_", "/"); if ($pluginAlias == false) { UTIL::addErr("The addJS Method was not called from a registered plugin"); return false; } $pluginLoader = new Plugins(); $pluginLoader->loadPlugins(); $plugins = $pluginLoader->getPluginsArray(); foreach ($plugins as $id => $pluginArray) { if ($pluginArray['alias'] == $pluginAlias) { VARS::$extraJS[] = PATH . "plugins/plugin_" . $pluginAlias . "/" . $jsPath; return true; } } } public static function addScriptJS($script) { VARS::$scriptJS = $script; } public static function addCSS($cssPath) { $debugArray = debug_backtrace(); $pluginAlias = UTIL::getBetween($debugArray[0]['file'], "/plugins/plugin_", "/"); if ($pluginAlias == false) { UTIL::addErr("The addCSS Method was not called from a registered plugin"); return false; } $pluginLoader = new Plugins(); $pluginLoader->loadPlugins(); $plugins = $pluginLoader->getPluginsArray(); foreach ($plugins as $id => $pluginArray) { if ($pluginArray['alias'] == $pluginAlias) { VARS::$extraCSS[] = PATH . "plugins/plugin_" . $pluginAlias . "/" . $cssPath; return true; } } } } class UTIL extends GeneralUTIL { public static function displayErrors($output) { if (VARS::$errors != false && is_array(VARS::$errors)) { $output = str_replace("<div id='errors' class='alert alert-danger'></div>", "<div id='errors' class='alert alert-danger'><h1>Uh Oh. Some errors occured!</h1>" . implode("<br>", VARS::$errors) . "</div>", $output); } else { $output = str_replace("<div id='errors' class='alert alert-danger'></div>", "", $output); } return $output; } /** * Custom JS /CSS functions * */ public static function addCustomJSFromPath($path) { VARS::$extraJS[] = PATH . $path; } public static function includeCustomCSS($output) { if (VARS::$extraCSS != false && is_array(VARS::$extraCSS)) { $css = ""; foreach (VARS::$extraCSS as $key => $path): $css .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$path\">\n"; endforeach; $output = str_replace("CUSTOMCSSAREAHERE", $css, $output); } else { $output = str_replace("CUSTOMCSSAREAHERE", "", $output); } return $output; } /** * Get Between two strings function * */ public static function getBetween($content, $start, $end) { if (preg_match('/' . str_replace("/", "\\/", $start) . '(.*?)' . str_replace("/", "\\/", $end) . '/', $content, $res) === false) { return false; } return $res[1]; } /** * Redirect page function * */ public static function redirect($location, $code = '302') { switch ($code) { case '301'; header("HTTP/1.1 301 Moved Permanently"); break; case '303'; header("HTTP/1.1 303 See Other"); break; case '404'; header('HTTP/1.1 404 Not Found'); break; } //remove any &amp; in the url to prevent any problems $location = str_replace('&amp;', '&', $location); header("Location: $location"); //kill the script from running and output a link for browsers which enable turning off header redirects *cough Opera cough* :P exit('<a href="' . $location . '">If you were not redirected automatically please click here</a>'); } }

preferences:
44.17 ms | 402 KiB | 5 Q