common_search.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 删除地址参数
  4. *
  5. * @param array $param
  6. */
  7. function dropParam($param) {
  8. $purl = getParam();
  9. if (!empty($param)) {
  10. foreach ($param as $val) {
  11. $purl['param'][$val] = 0;
  12. }
  13. }
  14. return urldecode(url('home/'.request()->controller().'/'.request()->action(),$purl['param']));
  15. }
  16. /**
  17. * 替换地址参数
  18. *
  19. * @param array $param
  20. */
  21. function replaceParam($param) {
  22. $purl = getParam();
  23. if (!empty($param)) {
  24. foreach ($param as $key => $val) {
  25. $purl['param'][$key] = $val;
  26. }
  27. }
  28. return urldecode(url('home/'.request()->controller().'/'.request()->action(),$purl['param']));
  29. }
  30. /**
  31. * 替换并删除地址参数
  32. *
  33. * @param array $param
  34. */
  35. function replaceAndDropParam($paramToReplace, $paramToDrop) {
  36. $purl = getParam();
  37. if (!empty($paramToReplace)) {
  38. foreach ($paramToReplace as $key => $val) {
  39. $purl['param'][$key] = $val;
  40. }
  41. }
  42. if (!empty($paramToDrop)) {
  43. foreach ($paramToDrop as $val) {
  44. $purl['param'][$val] = 0;
  45. }
  46. }
  47. return urldecode(url('home/'.request()->controller().'/'.request()->action(),$purl['param']));
  48. }
  49. /**
  50. * 删除部分地址参数
  51. *
  52. * @param array $param
  53. */
  54. function removeParam($param) {
  55. $purl = getParam();
  56. if (!empty($param)) {
  57. foreach ($param as $key => $val) {
  58. if (!isset($purl['param'][$key])) {
  59. continue;
  60. }
  61. $tpl_params = explode('_', $purl['param'][$key]);
  62. foreach ($tpl_params as $k => $v) {
  63. if ($val == $v) {
  64. unset($tpl_params[$k]);
  65. }
  66. }
  67. if (empty($tpl_params)) {
  68. $purl['param'][$key] = 0;
  69. } else {
  70. $purl['param'][$key] = implode('_', $tpl_params);
  71. }
  72. }
  73. }
  74. return urldecode(url('home/'.request()->controller().'/'.request()->action(),$purl['param']));
  75. }
  76. function getParam() {
  77. $param = input('param.');
  78. $purl = array();
  79. unset($param['page']);
  80. $param=str_replace('/','+',$param);
  81. SafeFilter($param);
  82. $purl['param'] = $param;
  83. return $purl;
  84. }
  85. function SafeFilter (&$arr)
  86. {
  87. $ra=Array('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/','/script/','/javascript/','/vbscript/','/expression/','/applet/','/meta/','/xml/','/blink/','/link/','/style/','/embed/','/object/','/frame/','/layer/','/title/','/bgsound/','/base/','/onload/','/onunload/','/onchange/','/onsubmit/','/onreset/','/onselect/','/onblur/','/onfocus/','/onabort/','/onkeydown/','/onkeypress/','/onkeyup/','/onclick/','/ondblclick/','/onmousedown/','/onmousemove/','/onmouseout/','/onmouseover/','/onmouseup/','/onunload/');
  88. if (is_array($arr))
  89. {
  90. foreach ($arr as $key => $value)
  91. {
  92. $new_key=$key;
  93. if (!is_array($value))
  94. {
  95. if (!get_magic_quotes_gpc())//不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  96. {
  97. $new_key=addslashes($new_key);
  98. $value = addslashes($value); //给单引号(')、双引号(")、反斜线(\)与NUL(NULL字符)加上反斜线转义
  99. }
  100. $new_key=preg_replace($ra,'',$new_key);
  101. $value = preg_replace($ra,'',$value); //删除非打印字符,粗暴式过滤xss可疑字符串
  102. $new_key=htmlentities(strip_tags($new_key));
  103. unset($arr[$key]);
  104. $arr[$new_key] = htmlentities(strip_tags($value)); //去除 HTML 和 PHP 标记并转换为HTML实体
  105. }
  106. else
  107. {
  108. SafeFilter($arr[$key]);
  109. }
  110. }
  111. }
  112. }
  113. ?>