checkprivs.php

来自「一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG」· PHP 代码 · 共 67 行

PHP
67
字号
<?phpdefined('WikyBlog') or die("Not an entry point...");	class checkPrivs{	function isGranted(){		if( !checkPrivs::isGrantedCheck() ){			message('To Continue with this script, you will need to grant Alter, Create, and Index privileges for your MySQL database user.');			return false;		}		return true;	}	function isGrantedCheck($which=array('CREATE','ALTER','INDEX')){		global $dbname;				$query = 'SHOW GRANTS;';		$result = wbDB::runQuery($query);		if( !$result ){			return false;		}		$num = mysql_num_rows($result);		if( $num < 1 ){			return false;		}				$privs = false;		while( $row = mysql_fetch_assoc($result) ){			$temp = current($row);			$temp = substr($temp,6); 			//strip "GRANT "						$pos = strpos($temp,' ON ');			$tempPrivs = substr($temp,0,$pos);						$temp = substr($temp,$pos+4);		//strip -pivs- and " ON "			$pos = strpos($temp,' TO ');			$tempON = substr($temp,0,$pos);			$tempON = str_replace(array('\_','\%'),array('_','%'),$tempON);						//message($tempON.' :: '.$tempPrivs);			if( $tempON == '`'.$dbname.'`.*'){				$privs = $tempPrivs;			}elseif( !$privs && $tempON == '*.*'){				$privs = $tempPrivs;			}		}				//		//	test the found privileges		//					if( !$privs ){				return true;			}			if( $privs  == 'ALL PRIVILEGES' ){				return true;			}			if( $privs == 'USAGE' ){				return false;			}			foreach($which as $priv){				if( strpos($privs,$priv) === false ){					return false;				}			}			return true;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?