phpMiniAdmin源码,mini mysql管理器,一段php代码搞定
代码语言:php
所属分类:其他
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php
/*
PHP Mini MySQL Admin
(c) 2004-2019 Oleg Savchuk <osalabs@gmail.com> http://osalabs.com
Light standalone PHP script for quick and easy access MySQL databases.
http://phpminiadmin.sourceforge.net
Dual licensed: GPL v2 and MIT, see texts at http://opensource.org/licenses/
*/
$ACCESS_PWD=''; #!!!IMPORTANT!!! this is script access password, SET IT if you want to protect you DB from public access
#DEFAULT db connection settings
# --- WARNING! --- if you set defaults - it's recommended to set $ACCESS_PWD to protect your db!
$DBDEF=array(
'user'=>"",#required
'pwd'=>"", #required
'db'=>"", #optional, default DB
'host'=>"",#optional
'port'=>"",#optional
'socket'=>"",#optional
'chset'=>"utf8",#optional, default charset
);
$IS_COUNT=false; #set to true if you want to see Total records when pagination occurs (SLOWS down all select queries!)
$DUMP_FILE=dirname(__FILE__).'/pmadump'; #path to file without extension used for server-side exports (timestamp, .sql/.csv/.gz extension added) or imports(.sql)
file_exists($f=dirname(__FILE__) . '/phpminiconfig.php')&&require($f); // Read from config (easier to update)
if (function_exists('date_default_timezone_set')) date_default_timezone_set('UTC');#required by PHP 5.1+
//constants
$VERSION='1.9.190822';
$MAX_ROWS_PER_PAGE=50; #max number of rows in select per one page
$D="\r\n"; #default delimiter for export
$BOM=chr(239).chr(187).chr(191);
$SHOW_D="SHOW DATABASES";
$SHOW_T="SHOW TABLE STATUS";
$DB=array(); #working copy for DB settings
$self=$_SERVER['PHP_SELF'];
session_set_cookie_params(0, null, null, false, true);
session_start();
if (!isset($_SESSION['XSS'])) $_SESSION['XSS']=get_rand_str(16);
$xurl='XSS='.$_SESSION['XSS'];
ini_set('display_errors',0); #turn on to debug db or script issues
error_reporting(E_ALL ^ E_NOTICE);
//strip quotes if they set
if (get_magic_quotes_gpc()){
$_COOKIE=array_map('killmq',$_COOKIE);
$_REQUEST=array_map('killmq',$_REQUEST);
}
if ($_REQUEST['login']){
if ($_REQUEST['pwd']!=$ACCESS_PWD){
$err_msg="Invalid password. Try again";
}else{
$_SESSION['is_logged']=true;
loadcfg();
}
}
if ($_REQUEST['logoff']){
check_xss();
$_SESSION = array();
savecfg();
session_destroy();
$url=$self;
if (!$ACCESS_PWD) $url='/';
header("location: $url");
exit;
}
if (!$_SESSION['is_logged']){
if (!$ACCESS_PWD) {
$_SESSION['is_logged']=true;
loadcfg();
}else{
print_login();
exit;
}
}
if ($_REQUEST['savecfg']){
check_xss();
savecfg();
}
loadsess();
if ($_REQUEST['showcfg']){
print_cfg();
exit;
}
//get initial values
$SQLq=trim(b64d($_REQUEST['q']));
$page=$_REQUEST['p']+0;
if ($_REQUEST['refresh'] && $DB['db'] && preg_match('/^show/',$SQLq) ) $SQLq=$SHOW_T;
if (db_connect('nodie')){
$time_start=microtime_float();
if ($_REQUEST['pi']){
ob_start();phpinfo();$html=ob_get_clean();preg_match("/<body[^>]*>(.*?)<\/body>/is",$html,$m);
$sqldr='<div class="pi">'.$m[1].'</div>';
}else{
if ($DB['db']){
if ($_REQUEST['shex']){
print_export();
}elseif ($_REQUEST['doex']){
check_xss();do_export();
}elseif ($_REQUEST['shim']){
print_import();
}elseif ($_REQUEST['doim']){
check_xss();do_import();
}elseif ($_REQUEST['dosht']){
check_xss();do_sht();
}elseif (!$_REQUEST['refresh'] || preg_match('/^select|show|explain|desc/i',$SQLq) ){
if ($SQLq)check_xss();
do_sql($SQLq);#perform non-select SQL only if not refresh (to avoid dangerous delete/drop)
}
}else{
if ( $_REQUEST['refresh'] ){
check_xss();do_sql($SHOW_D);
}elseif ($_REQUEST['crdb']){
check_xss();do_sql('CREATE DATABASE `'.$_REQUEST['new_db'].'`');do_sql($SHOW_D);
}elseif ( preg_match('/^(?:show\s+(?:databases|status|variables|process)|create\s+database|grant\s+)/i',$SQLq) ){
check_xss();do_sql($SQLq);
}else{
$err_msg="Select Database first";
if (!$SQLq) do_sql($SHOW_D);
}
}
}
$time_all=ceil((microtime_float()-$time_start)*10000)/10000;
print_screen();
}else{
print_cfg();
}
function do_sql($q){
global $dbh,$last_sth,$last_sql,$reccount,$out_message,$SQLq,$SHOW_T;
$SQLq=$q;
if (!do_multi_sql($q)){
$out_message="Error: ".mysqli_error($dbh);
}else{
if ($last_sth && $last_sql){
$SQLq=$last_sql;
if (preg_match("/^.........完整代码请登录后点击上方下载按钮下载查看















网友评论0