php单文件版在线代码编辑器

前端之家收集整理的这篇文章主要介绍了php单文件版在线代码编辑器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

密码加密方式: * md5(自设密码+$ace) //$ace为cdn镜像地址

使用方法:

* 1.确认 $pwd 变量值为 false,上传文件PHP空间并访问 * 2.第一次访问提示设置密码,设置密码并牢记 * 3.使用第一次设置的密码登录后,默认编辑的是本PHP文件, * 4.本文件是编辑器核心文件,请不要随意修改 * 5.保存编辑的文件请用 Ctrl + S 按键组合,等待执行结果 * 6.保存动作执行后请务必等待保存成功信息返回 * 7.重置操作会修改本程序的文件名,以防他人猜测路径 * 8.刷新功能仅是刷新本程序文件,不能刷新其他

建议在 chrome 浏览器中使用本编辑器

代码如下:
'actionscript','js' => 'javascript', 'PHP' => 'PHP','css' => 'css','html' => 'html', 'htm' => 'html','ini' => 'ini','json' => 'json', 'jsp' => 'jsp','txt' => 'text','sql' => 'MysqL', 'xml' => 'xml','yaml' => 'yaml','py' => 'python', 'md' => 'markdown','htaccess' => 'apache_conf', 'bat' => 'batchfile','go' => 'golang', ); //判断用户是否登录 function is_logged() { $flag = false; if ( isset($_SESSION['pwd']) && defined('DEFAULT_PWD') ) { if ( $_SESSION['pwd'] === DEFAULT_PWD ) { $flag = true; } } return $flag; } //重新载入到本页面 function reload() { $file = pathinfo(__FILE__,PATHINFO_BASENAME); die(header("Location: {$file}")); } //判断请求是否是ajax请求 function is_ajax() { $flag = false; if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) { $flag = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'; } return $flag; } //销毁SESSION和COOKIE function exterminate() { $_SESSION = array(); foreach ( $_COOKIE as $key ) { setcookie($key,null); } session_destroy(); $_COOKIE = array(); return true; } //获取一个目录下的文件列表 function list_dir($path,$type = 'array') { $flag = false; $lst = array('dir'=>array(),'file'=>array()); $base = !is_dir($path) ? dirname($path) : $path; $tmp = scandir($base); foreach ( $tmp as $k=>$v ) { //过滤掉上级目录,本级目录和程序自身文件名 if ( !in_array($v,array('.','..')) ) { $file = $full_path = rtrim($base,'/').DIRECTORY_SEPARATOR.$v; if ( $full_path == __FILE__ ) { continue; //屏蔽自身文件不在列表出现 } $file = str_replace(dirname(__FILE__),$file); $file = str_replace("\\",'/',$file); //过滤win下的路径 $file = str_replace('//',$file); //过滤双斜杠 if ( is_dir($full_path) ) { if ( 'html' === $type ) { $v = '
  • '.$v.'
  • '; } array_push($lst['dir'],$v); } else { if ( 'html' === $type ) { $v = '
  • '.$v.'
  • '; } array_push($lst['file'],$v); } } } $lst = array_merge($lst['dir'],$lst['file']); $lst = array_filter($lst); $flag = $lst; if ( 'html' === $type ) { $flag = '
      '. implode('',$lst) .'
    '; } return $flag; } //递归删除一个非空目录 function deldir($dir) { $dh = opendir($dir); while ( $file = readdir($dh) ) { if ( $file != '.' && $file != '..' ) { $fullpath = $dir.'/'.$file; if ( !is_dir($fullpath) ) { unlink($fullpath); } else { deldir($fullpath); } } } return rmdir($dir); } //退出登录 if ( isset($_GET['logout']) ) { if ( exterminate() ) { reload(); } } //ajax输出文件内容 if ( is_logged() && is_ajax() && isset($_POST['file']) ) { $file = dirname(__FILE__).$_POST['file']; $ext = pathinfo($file,PATHINFO_EXTENSION); $mode = isset($lng[$ext]) ? $lng[$ext] : false; die(json_encode(array( 'file' => $file,'html' => file_get_contents($file), 'mode' => $mode, ))); } //ajax输出目录列表 if ( is_logged() && is_ajax() && isset($_POST['dir']) ) { $dir = dirname(__FILE__).$_POST['dir']; $list_dir = list_dir($dir,'html'); die(json_encode(array( 'dir' => $dir,'html' => $list_dir, ))); } //ajax保存文件 if ( is_logged() && is_ajax() && isset($_POST['action']) ) { $arr = array('result'=>'error','msg'=>'文件保存失败!'); $content = $_POST['content']; if ( 'save_file' === $_POST['action'] ) { if ( isset($_POST['file_path']) ) { $file = dirname(__FILE__).$_POST['file_path']; } else { $file = __FILE__; } file_put_contents($file,$content); $arr['result'] = 'success'; $arr['msg'] = '保存成功!'; } die(json_encode($arr)); } //ajax删除文件文件夹 if ( is_logged() && is_ajax() && isset($_POST['del']) ) { $path = dirname(__FILE__).$_POST['del']; $arr = array('result'=>'error','msg'=>'删除操作失败!'); if ( $_POST['del'] && $path ) { $flag = is_dir($path) ? deldir($path) : unlink($path); if ( $flag ) { $arr['msg'] = '删除操作成功!'; $arr['result'] = 'success'; } } die(json_encode($arr)); } //ajax新建文件文件夹 if ( is_logged() && is_ajax() && isset($_POST['create']) ) { $flag = false; $arr = array('result'=>'error','msg'=>'操作失败!'); if ( isset($_POST['target']) ) { $target = dirname(__FILE__).$_POST['target']; $target = is_dir($target) ? $target : dirname($target); } if ( $_POST['create'] && $target ) { $base_name = pathinfo($_POST['create'],PATHINFO_BASENAME); $exp = explode('.',$base_name); $full_path = $target.'/'.$base_name; $new_path = str_replace(dirname(__FILE__),$full_path); if ( count($exp) > 1 && isset($lng[array_pop($exp)]) ) { file_put_contents($full_path,''); $arr['result'] = 'success'; $arr['msg'] = '新建文件成功!'; $arr['type'] = 'file'; } else { mkdir($full_path,0777,true); $arr['result'] = 'success'; $arr['msg'] = '新建目录成功!'; $arr['type'] = 'dir'; } if ( $base_name && $new_path ) { $arr['new_name'] = $base_name; $arr['new_path'] = $new_path; } } die(json_encode($arr)); } //ajax重命名文件文件夹 if ( is_logged() && is_ajax() && isset($_POST['rename']) ) { $arr = array('result'=>'error','msg'=>'重命名操作失败!'); if ( isset($_POST['target']) ) { $target = dirname(__FILE__).$_POST['target']; } if ( $_POST['rename'] ) { $base_name = pathinfo($_POST['rename'],PATHINFO_BASENAME); if ( $base_name ) { $rename = dirname($target).'/'.$base_name; $new_path = str_replace(dirname(__FILE__),$rename); } } if ( $rename && $target && rename($target,$rename) ) { $arr['new_name'] = $base_name; $arr['new_path'] = $new_path; $arr['msg'] = '重命名操作成功!'; $arr['result'] = 'success'; } if ( $target == __FILE__ ) { $arr['redirect'] = $new_path; } die(json_encode($arr)); } //获取代码文件内容 $code = file_get_contents($curr_file); $tree = '
    '; //登陆和设置密码共用模版 $first = << <Meta charset="UTF-8"> 【<a href="https://www.jb51.cc/tag/biaoti/" target="_blank" class="keywords">标题</a>】 <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    logout">
    
    
    
    HTMLSTR;
    //判断是否已经登录
    if ( !is_logged() ) {
     die(str_replace(
     array('【标题】',
     array('请输入您第一次设置的密码!','登录'),
     $first
     )); 
    } else {
     echo $html;
    }
    

    以上就是本文所述的全部内容了,希望大家能够喜欢。

    原文链接:https://www.f2er.com/php/22474.html

    猜你在找的PHP相关文章