global.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. header("Content-type: text/html; charset=utf8");
  3. error_reporting(0);
  4. ob_start();
  5. $magic_quotes_gpc = get_magic_quotes_gpc();
  6. @extract(daddslashes($_POST));
  7. @extract(daddslashes($_GET));
  8. define("PHPOK_SET",true);
  9. function sys_md5($rs)
  10. {
  11. if(!$rs)
  12. {
  13. return false;
  14. }
  15. $rs = is_array($rs) ? implode("[:phpok:]",$rs) : $rs;
  16. return md5(md5($rs));
  17. }
  18. function daddslashes($string, $force = 0)
  19. {
  20. if(!$GLOBALS["magic_quotes_gpc"] || $force)
  21. {
  22. if(is_array($string))
  23. {
  24. foreach($string as $key => $val)
  25. {
  26. $string[$key] = daddslashes($val, $force);
  27. }
  28. }
  29. else
  30. {
  31. $string = addslashes($string);
  32. }
  33. }
  34. return $string;
  35. }
  36. Function format_sql($sql)
  37. {
  38. global $db;
  39. $sql = str_replace("\r","\n",$sql);
  40. $ret = array();
  41. $num = 0;
  42. foreach(explode(";\n", trim($sql)) as $query) {
  43. $queries = explode("\n", trim($query));
  44. foreach($queries as $query) {
  45. $ret[$num] .= $query[0] == '#' || $query[0].$query[1] == '--' ? '' : $query;
  46. }
  47. $num++;
  48. }
  49. unset($sql);
  50. foreach($ret as $query) {
  51. $query = trim($query);
  52. if($query) {
  53. if(substr($query, 0, 12) == 'CREATE TABLE') {
  54. //$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  55. //echo '创建表:'.$name.' ... <font color="#0000EE">'.$lang['succeed'].'</font><br>';
  56. $db->query(create_table($query));
  57. } else {
  58. $db->query($query);
  59. }
  60. }
  61. }
  62. }
  63. function create_table($sql)
  64. {
  65. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).(mysql_get_server_info() > '4.1' ? " ENGINE=MyISAM DEFAULT CHARSET=utf8" : " TYPE=MYISAM");
  66. }
  67. function check_write($file)
  68. {
  69. if(is_writeable($file))
  70. {
  71. return "<span style='color:darkgreen;font:bold 15px Tahoma,Arial;'>√</span>";
  72. }
  73. else
  74. {
  75. return "<span style='color:red;font:bold 15px Tahoma,Arial;'>×</span>";
  76. }
  77. }
  78. function safe_html($msg = "")
  79. {
  80. if(empty($msg))
  81. {
  82. return false;
  83. }
  84. $msg = str_replace('&amp;','&',$msg);
  85. $msg = str_replace('&nbsp;',' ',$msg);
  86. $msg = str_replace("'","&#39;",$msg);
  87. $msg = str_replace('"',"&quot;",$msg);
  88. $msg = str_replace("<","&lt;",$msg);
  89. $msg = str_replace(">","&gt;",$msg);
  90. $msg = str_replace("\t","&nbsp; &nbsp; ",$msg);
  91. $msg = str_replace("\r","",$msg);
  92. $msg = str_replace(" ","&nbsp; &nbsp;",$msg);
  93. return $msg;
  94. }
  95. function getip()
  96. {
  97. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
  98. {
  99. $onlineip = getenv('HTTP_CLIENT_IP');
  100. }
  101. elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
  102. {
  103. $onlineip = getenv('HTTP_X_FORWARDED_FOR');
  104. }
  105. elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
  106. {
  107. $onlineip = getenv('REMOTE_ADDR');
  108. }
  109. elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown'))
  110. {
  111. $onlineip = $_SERVER['REMOTE_ADDR'];
  112. }
  113. return $onlineip;
  114. }
  115. function file_put_msg($file="",$content="")
  116. {
  117. if(!$file || !$content)
  118. {
  119. return false;
  120. }
  121. if(function_exists("file_put_contents"))
  122. {
  123. file_put_contents($file,$content);
  124. }
  125. else
  126. {
  127. $handle = fopen($file,"wb");
  128. fwrite($handle,$content);
  129. fclose($handle);
  130. }
  131. return true;
  132. }
  133. if(!function_exists("base_url"))
  134. {
  135. function base_url()
  136. {
  137. $myurl = "http://".str_replace("http://","",$_SERVER["SERVER_NAME"]);
  138. $docu = $_SERVER["PHP_SELF"];
  139. $array = explode("/",$docu);
  140. $count = count($array);
  141. if($count>1)
  142. {
  143. foreach($array AS $key=>$value)
  144. {
  145. $value = trim($value);
  146. if($value)
  147. {
  148. if(($key+1) < $count)
  149. {
  150. $myurl .= "/".$value;
  151. }
  152. }
  153. }
  154. }
  155. $myurl .= "/";
  156. return $myurl;
  157. }
  158. }
  159. require_once("../libs/tpl_engine/et.tpl.php");
  160. $tplarray = array();
  161. $tplarray["tplid"] = 1;
  162. $tplarray["tpldir"] = "tpl";
  163. $tplarray["cache"] = "tpl_c";
  164. $tplarray["ext"] = "html";
  165. $tplarray["autoimg"] = true;
  166. $tpl = new et_tpl($tplarray);
  167. $APP->tpl = $tpl;
  168. unset($tplarray);
  169. function error($title="",$url="")
  170. {
  171. global $tpl;
  172. global $APP;
  173. $tpl->assign("APP",$APP);
  174. $tpl->assign("content",$title);
  175. $tpl->assign("url",$url);
  176. $tpl->display("error.html");
  177. exit();
  178. }
  179. ?>