示例#1
0
/**
 * 将错误记录到日志
 * Enter description here ...
 */
function logErrorToFile($errno, $errstr, $errfile, $errline)
{
    $errStr = date('Y-m-d H:i:s') . " | 文件 {$errfile} | 第 {$errline} 行 | 错误级别 " . getErrorName($errno) . " | 错误信息 {$errstr} \n";
    $path = defined(LOG_ERROR_PATH) ? LOG_ERROR_PATH : './log';
    if (!is_dir($path)) {
        mkdir($path, 0777, true);
    }
    $fileName = rtrim($path, '/') . '/' . date('Ym') . '.err';
    touch($fileName);
    //更新文件访问时间,如果不存在则创建
    $fp = fopen($fileName, 'a');
    fwrite($fp, $errStr);
    //写入文件
    fclose($fp);
    //应该判断错误级别,跳转到错误页面
    header("location:" . U('error'));
}
示例#2
0
文件: eval.php 项目: inureyes/editor
header('Content-Type: text/html; charset=utf-8');
if (isset($_POST['code']) === true) {
    $code = (string) $_POST['code'];
    // remove PHP start and end tags
    $code = preg_replace('/^<\\?php(.*)(\\?>)?$/s', '$1', $code);
    $code = trim($code);
    // output buffered evaluation
    ob_start();
    eval($code);
    $buffer = ob_get_clean();
    // error handling
    $error = error_get_last();
    if ($error > 0) {
        // errors contains: type, message, file, line
        // now we add the error "type" as "error" with a friendly error name
        $error['error'] = getErrorName($error['type']);
        $jsonError = json_encode($error, true);
        /* Send the error
             - name as text/html (to the codemirror-result area)
             - array as json via header
           */
        echo strtoupper($error['error']);
        header('Z-Error: ' . $jsonError);
    } else {
        echo $buffer;
    }
}
function getErrorName($errorInt)
{
    $errortypes = array(E_ERROR => 'error', E_WARNING => 'warning', E_PARSE => 'parsing error', E_NOTICE => 'notice', E_CORE_ERROR => 'core error', E_CORE_WARNING => 'core warning', E_COMPILE_ERROR => 'compile error', E_COMPILE_WARNING => 'compile warning', E_USER_ERROR => 'user error', E_USER_WARNING => 'user warning', E_USER_NOTICE => 'user notice');
    return $errortypes[$errorInt];
示例#3
0
$code = urldecode($_POST['code']);
if (!empty($code)) {
    if (get_magic_quotes_gpc()) {
        $code = stripslashes($code);
    }
    ob_start();
    list($usec, $sec) = explode(" ", microtime());
    $start = (double) $usec + (double) $sec;
    eval($code);
    list($usec, $sec) = explode(" ", microtime());
    $end = (double) $usec + (double) $sec;
    if (isset($start)) {
        $timeTaken = round($end - $start, 4);
    } else {
        $timeTaken = '?';
    }
    $result = ob_get_clean();
    $error = error_get_last();
    $isError = isset($error['type']) && false !== stripos(getErrorName($error['type']), 'error');
    $result = array('time' => $timeTaken, 'line' => $error['line'], 'result' => $result);
    if ($isError) {
        $result['line'] = $error['line'];
        $result['result'] = getErrorName($error['type']) . ' : ' . $error['message'];
    }
    echo json_encode($result);
}
function getErrorName($errorCode)
{
    $errortypes = array(E_NOTICE => 'NOTICE', E_ERROR => 'ERROR', E_USER_NOTICE => 'USER NOTICE', E_WARNING => 'WARNING', E_PARSE => 'PARSE ERROR', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING');
    return $errortypes[$errorCode];
}