daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest May 16th, 2018 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. class Tools
  5. {
  6.     /**
  7.      * get cleaned up var
  8.      * @param string post/get associative array key
  9.      * @return mixed
  10.      */
  11.     public static function getValue($key)
  12.     {
  13.         if(isset($_GET[$key])) {
  14.             $val = $_GET[$key];
  15.         } else if(isset($_POST[$key])) {
  16.             $val = $_POST[$key];
  17.         } else {
  18.             $val = false;
  19.         }
  20.        
  21.         $val = self::sanitize($val);
  22.        
  23.         return $val;
  24.     }
  25.    
  26.     /**
  27.      * clean up field or fiels
  28.      * @param string|array $var
  29.      * @return string|array
  30.      */
  31.     public static function sanitize(&$var)
  32.     {
  33.         if(is_array($var)) {
  34.             foreach($var as &$v) {
  35.                 self::sanitize($v);
  36.             }
  37.         } else {
  38.             $var = htmlspecialchars($var);
  39.         }
  40.        
  41.         return $var;
  42.     }
  43.  
  44.     /**
  45.      *  Get final redirect url - prepare url for pass GET data,
  46.      *  can be used to make sure about http/https or different languages
  47.      *  without redirects.
  48.      *  
  49.      * @param string $url - url to check
  50.      * @return string new final url after all inner redirects
  51.      */    
  52.     public static function getRedirectUrl ($url)
  53.     {
  54.         stream_context_set_default(array(
  55.            'http' => array(
  56.                'method' => 'HEAD'
  57.            )
  58.         ));
  59.        
  60.         $headers = get_headers($url, 1);
  61.         if ($headers !== false && isset($headers['Location'])) {
  62.             return $headers['Location'];
  63.         }
  64.  
  65.         return false;
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top