conn.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. // 设置编码
  3. session_start();
  4. header('Content-Type: text/html; charset=utf-8');
  5. header('Cache-Control: no-cache');
  6. date_default_timezone_set('Asia/Shanghai');
  7. // 数据库连接
  8. $conn = new mysqli("127.0.0.1", "crm", "Qweasdzxc", "crm_new");
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12. $conn->set_charset("utf8mb4");
  13. // 检查登录
  14. function checkLogin() {
  15. if (empty($_SESSION['employee_id'])) {
  16. echo "<script>top.location.href='index.php'</script>";
  17. exit;
  18. }
  19. }
  20. // 获取IP
  21. function getIp() {
  22. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
  23. if (strlen($ip) > 15) {
  24. $ip = "UnKnow";
  25. }
  26. return htmlspecialcharsFix($ip);
  27. }
  28. // 移除HTML
  29. function removeHTML($t0) {
  30. if (empty($t0)) {
  31. return "";
  32. }
  33. $t0 = preg_replace("/<script.+?\/script>/is", "", $t0);
  34. $t0 = preg_replace("/<iframe.+?\/iframe>/is", "", $t0);
  35. $t0 = str_replace(["&lt;", "&gt;", "&nbsp;"], ["<", ">", ""], $t0);
  36. $t0 = preg_replace("/<.+?>/", "", $t0);
  37. return str_replace(["\r\n", "\t", "\r", "\n"], "", $t0);
  38. }
  39. // Text转HTML
  40. function txt2HTML($t0) {
  41. if (empty($t0) || is_array($t0)) {
  42. return "";
  43. }
  44. return str_replace(
  45. ["&", "\"", "<", ">", " "],
  46. ["&amp;", "&quot;", "&lt;", "&gt;", "&nbsp;"],
  47. $t0
  48. );
  49. }
  50. // HTML转Text
  51. function html2Txt($t0) {
  52. if (empty($t0) || is_array($t0)) {
  53. return "";
  54. }
  55. return str_replace(
  56. ["&quot;", "&lt;", "&gt;", "&nbsp;", "&amp;"],
  57. ["\"", "<", ">", " ", "&"],
  58. $t0
  59. );
  60. }
  61. // HTML编码
  62. function htmlEncode($t0) {
  63. if (empty($t0) || is_array($t0)) {
  64. return "";
  65. }
  66. $replacements = [
  67. chr(38) => "&#38;", chr(9) => "&#9;", chr(11) => "&#11;",
  68. chr(10) => "&#10;", chr(13) => "&#13;", chr(32) => "&#32;",
  69. chr(34) => "&#34;", chr(37) => "&#37;", chr(39) => "&#39;",
  70. chr(40) => "&#40;", chr(41) => "&#41;", chr(60) => "&#60;",
  71. chr(62) => "&#62;", chr(91) => "&#91;", chr(93) => "&#93;",
  72. chr(94) => "&#94;", chr(95) => "&#95;", chr(123) => "&#123;",
  73. chr(124) => "&#124;", chr(125) => "&#125;"
  74. ];
  75. return strtr($t0, $replacements);
  76. }
  77. // HTML解码
  78. function htmlUnCode($t0) {
  79. if (empty($t0) || is_array($t0)) {
  80. return "";
  81. }
  82. $replacements = [
  83. "&#9;" => chr(9), "&#11;" => chr(11), "&#10;" => chr(10),
  84. "&#13;" => chr(13), "&#32;" => chr(32), "&#34;" => chr(34),
  85. "&#37;" => chr(37), "&#39;" => chr(39), "&#40;" => chr(40),
  86. "&#41;" => chr(41), "&#60;" => chr(60), "&#62;" => chr(62),
  87. "&#91;" => chr(91), "&#93;" => chr(93), "&#94;" => chr(94),
  88. "&#95;" => chr(95), "&#123;" => chr(123), "&#124;" => chr(124),
  89. "&#125;" => chr(125), "&#38;" => chr(38)
  90. ];
  91. return strtr($t0, $replacements);
  92. }
  93. // 文本编码
  94. function textEncode($t0) {
  95. if (empty($t0) || is_array($t0)) {
  96. return "";
  97. }
  98. $t0 = trim($t0);
  99. $remove = [chr(8), chr(9), chr(11), chr(12), chr(10), chr(13)];
  100. $t0 = str_replace($remove, "", $t0);
  101. $replacements = [
  102. chr(38) => "&#38;", chr(47) => "&#47;", chr(32) => "&#32;",
  103. chr(34) => "&#34;", chr(37) => "&#37;", chr(39) => "&#39;",
  104. chr(40) => "&#40;", chr(41) => "&#41;", "(" => "&#40;",
  105. ")" => "&#41;", chr(60) => "&#60;", chr(62) => "&#62;",
  106. chr(91) => "&#91;", chr(93) => "&#93;", chr(94) => "&#94;",
  107. chr(95) => "&#95;", chr(123) => "&#123;", chr(124) => "&#124;",
  108. chr(125) => "&#125;"
  109. ];
  110. return strtr($t0, $replacements);
  111. }
  112. // 数字格式化
  113. function numFormat($t0) {
  114. if (empty($t0) || is_array($t0)) {
  115. return "";
  116. }
  117. $t0 = trim($t0);
  118. $remove = ["-", "+", "&#32;", "&", " ", chr(34), "*", "%", "'", "(", ")", "<", ">",
  119. "[", "]", "^", "_", "{", "\\", "/", "|", "}", "(", ")"];
  120. return str_replace($remove, "", $t0);
  121. }
  122. // 文本解码
  123. function textUncode($t0) {
  124. if (empty($t0) || is_array($t0)) {
  125. return "";
  126. }
  127. $replacements = [
  128. "&#32;" => chr(32), "&#34;" => chr(34), "&#37;" => chr(37),
  129. "&#39;" => chr(39), "&#40;" => chr(40), "&#41;" => chr(41),
  130. "&#60;" => chr(60), "&#62;" => chr(62), "&#91;" => chr(91),
  131. "&#93;" => chr(93), "&#94;" => chr(94), "&#95;" => chr(95),
  132. "&#123;" => chr(123), "&#124;" => chr(124), "&#125;" => chr(125),
  133. "&#47;" => chr(47), "&#38;" => chr(38)
  134. ];
  135. return strtr($t0, $replacements);
  136. }
  137. // HTML解码1
  138. function htmlUnCode1($t0) {
  139. if (empty($t0) || is_array($t0)) {
  140. return "";
  141. }
  142. $replacements = [
  143. "&#9;" => chr(9), "&#11;" => chr(11), "&#13;&#10;" => "<br />",
  144. "&#10;" => "<br />", "&#13;" => "<br />", "&#32;" => "&nbsp;",
  145. "&#38;" => chr(38)
  146. ];
  147. return strtr($t0, $replacements);
  148. }
  149. // 格式化时间
  150. function formatTime($ttime, $tparam) {
  151. if (!strtotime($ttime)) {
  152. return "";
  153. }
  154. $date = new DateTime($ttime);
  155. $tsrt = $tparam;
  156. $replacements = [
  157. "yyyy" => $date->format("Y"),
  158. "yy" => $date->format("y"),
  159. "mm" => $date->format("m"),
  160. "dd" => $date->format("d"),
  161. "hh" => $date->format("H"),
  162. "ff" => $date->format("i"),
  163. "ss" => $date->format("s"),
  164. "m" => $date->format("n"),
  165. "d" => $date->format("j"),
  166. "h" => $date->format("G"),
  167. "f" => $date->format("i"),
  168. "s" => $date->format("s")
  169. ];
  170. return strtr($tsrt, $replacements);
  171. }
  172. // 英文月份
  173. function enMonth($m) {
  174. $months = [
  175. "1" => "Jan", "2" => "Feb", "3" => "Mar", "4" => "Apr",
  176. "5" => "May", "6" => "Jun", "7" => "Jul", "8" => "Aug",
  177. "9" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec"
  178. ];
  179. return $months[$m] ?? "Dec";
  180. }
  181. // 字符串截取
  182. function strLeft($str, $strLen) {
  183. if (empty($str)) {
  184. return "";
  185. }
  186. $length = 0;
  187. $result = "";
  188. for ($i = 0; $i < mb_strlen($str); $i++) {
  189. $char = mb_substr($str, $i, 1);
  190. $length += (mb_ord($char) > 255) ? 2 : 1;
  191. if ($length > $strLen) {
  192. return $result . "..";
  193. }
  194. $result .= $char;
  195. }
  196. return $result;
  197. }
  198. // 验证邮箱
  199. function isValidEmail($email) {
  200. $names = explode("@", $email);
  201. if (count($names) !== 2) {
  202. return false;
  203. }
  204. foreach ($names as $name) {
  205. if (empty($name)) {
  206. return false;
  207. }
  208. if (preg_match("/[^a-z0-9_.-]/", strtolower($name))) {
  209. return false;
  210. }
  211. if (str_starts_with($name, ".") || str_ends_with($name, ".")) {
  212. return false;
  213. }
  214. }
  215. $domainParts = explode(".", $names[1]);
  216. if (count($domainParts) < 2) {
  217. return false;
  218. }
  219. $tldLength = strlen(end($domainParts));
  220. if ($tldLength !== 2 && $tldLength !== 3) {
  221. return false;
  222. }
  223. if (str_contains($email, "..")) {
  224. return false;
  225. }
  226. return true;
  227. }
  228. // 站点链接替换
  229. function sitelink_replace($t0, $t1, $t2, $t3) {
  230. if (empty($t0)) {
  231. return "";
  232. }
  233. $t4 = $t0;
  234. $pattern = "/(\<a[^<>]+\>.+?\<\/a\>)|(\<img[^<>]+\>)|(\<h[1-6]+[\s]*\>.+?\<\/h[1-6]+\>)/i";
  235. preg_match_all($pattern, $t4, $matches);
  236. $myarray = [];
  237. if (count($matches[0]) > 0) {
  238. foreach ($matches[0] as $i => $match) {
  239. $myarray[$i] = $match;
  240. $t4 = str_replace($match, "[$i]", $t4, $t3);
  241. }
  242. }
  243. if (empty($myarray)) {
  244. return str_replace($t1, $t2, $t0, $t3);
  245. }
  246. $t4 = str_replace($t1, $t2, $t4, $t3);
  247. foreach ($myarray as $i => $value) {
  248. $t4 = str_replace("[$i]", $value, $t4, $t3);
  249. }
  250. return $t4;
  251. }
  252. //处理特殊字符
  253. function htmlspecialcharsFix($input_str)
  254. {
  255. return $input_str;
  256. }