Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 3rd, 2012  |  syntax: PHP  |  size: 2.96 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*
  4. *
  5. * Autoloads Classes
  6. *
  7. */
  8. function __autoload($classname) {
  9.     include_once('classes/'.$classname.'.class.php');
  10. }
  11.  
  12. /*
  13. *
  14. * String processing container functions
  15. *
  16. */
  17. function cleanInput($input) {
  18.     if (is_array($input)) {
  19.         foreach($input as $var=>$val) {
  20.             $output[$var] = cleanScript($val);
  21.         }
  22.     }
  23.     else {
  24.         if (get_magic_quotes_gpc()) {
  25.             $input = stripslashes($input);
  26.         }
  27.         $input  = cleanScript($input);
  28.         $input = mysql_real_escape_string($input);
  29.         $input = str_replace('\r\n', "<br>", $input);
  30.     }
  31.     return $input;
  32. }
  33.  
  34. function cleanScript($input) {
  35.  $search = array(
  36.   '@<script[^>]*?>.*?</script>@si'   // Strip out javascript
  37.  );
  38.  
  39.  $output = preg_replace($search, '', $input);
  40.  $output = str_replace(array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'), "", $output);
  41.  return $output;
  42. }
  43.  
  44. /*
  45. *
  46. *    Messages: Alerts, Errors, Success, Info
  47. *
  48. */
  49. function addMessage($message, $messageType="success2")
  50. {
  51.     $_SESSION['message'] = $message;
  52.     $_SESSION['messageType'] = $messageType;
  53. }
  54.  
  55. function clearMessages()
  56. {
  57.     unset($_SESSION['message']);
  58.     unset($_SESSION['messageType']);
  59. }
  60.  
  61. function getVar($var) {
  62.         $return = 0;
  63.  
  64.         if(isset($_GET[$var]))
  65.                 $return = cleanInput($_GET[$var]);
  66.                
  67.         if(isset($_POST[$var]))
  68.                 $return = cleanInput($_POST[$var]);
  69.        
  70.     if(!isset($_GET[$var]) && !isset($_POST[$var])):
  71.         $return = !getUrlVar($var)?$return:getUrlVar($var);
  72.     endif;
  73.    
  74.         return $return;
  75. }
  76.  
  77. function getUrlVar($key) {
  78.     // Get the requested URL
  79.     $request  = $_SERVER['REQUEST_URI'];
  80.  
  81.     // split the path by '/'  
  82.     $params = explode("/", $request);
  83.    
  84.     $key = array_search($key, $params);
  85.     if($key === FALSE)
  86.         return false;
  87.     else
  88.         return isset($params[$key + 1])?$params[$key + 1]:true;
  89. }
  90.  
  91. ?>