common.php 815 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // 应用公共文件
  3. $error_custom= '111';
  4. function validateEmail($email): bool
  5. {
  6. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  7. return false;
  8. } else {
  9. return true;
  10. }
  11. }
  12. function uuid(): string
  13. {
  14. $chars = md5(uniqid(mt_rand(), true));
  15. return substr($chars, 0, 8) . '-'
  16. . substr($chars, 8, 4) . '-'
  17. . substr($chars, 12, 4) . '-'
  18. . substr($chars, 16, 4) . '-'
  19. . substr($chars, 20, 12);
  20. }
  21. function renderToken($t = 'tab'): string
  22. {
  23. $s = uuid() . strval(time()) . $t;
  24. return md5($s);
  25. }
  26. function joinPath($path1, $path2)
  27. {
  28. return preg_replace("#//#", "/", $path1 . $path2);
  29. }
  30. function getRealIp()
  31. {
  32. $ip1 = request()->header('x-forwarded-for', false);
  33. if ($ip1) {
  34. return $ip1;
  35. }
  36. return request()->ip();
  37. }