common.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * Common Class
  4. * by lijg 20181029
  5. */
  6. class CommonLib{
  7. public function __construct(){
  8. //TODO
  9. }
  10. //rearrange array for multiple upload array
  11. public function reArrArr($arr = array()){
  12. if(empty($arr)){
  13. return false;
  14. }
  15. $newArr = array();
  16. foreach($arr as $fkey => $fval){
  17. foreach($fval as $fk => $fv){
  18. $newArr[$fk][$fkey] = $fv;
  19. }
  20. }
  21. return $newArr;
  22. }
  23. public function my_filter_input($ipt){
  24. if($ipt == null){
  25. return false;
  26. }
  27. $ipt = trim($ipt);
  28. $ipt = stripslashes($ipt);
  29. $ipt = htmlspecialchars($ipt);
  30. return $ipt;
  31. }
  32. public function getIp(){
  33. $ip = '';
  34. $m = array();
  35. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  36. $ip = getenv('HTTP_CLIENT_IP');
  37. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  38. $ip = getenv('HTTP_X_FORWARDED_FOR');
  39. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  40. $ip = getenv('REMOTE_ADDR');
  41. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  42. $ip = $_SERVER['REMOTE_ADDR'];
  43. }
  44. $ip = preg_match( '/[\d\.]{7,15}/',$ip, $m)?$m[0]:'';
  45. return $ip;
  46. }
  47. public function __destruct(){
  48. //TODO
  49. }
  50. }