Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Tools
- {
- /**
- * get cleaned up var
- * @param string post/get associative array key
- * @return mixed
- */
- public static function getValue($key)
- {
- if(isset($_GET[$key])) {
- $val = $_GET[$key];
- } else if(isset($_POST[$key])) {
- $val = $_POST[$key];
- } else {
- $val = false;
- }
- $val = self::sanitize($val);
- return $val;
- }
- /**
- * clean up field or fiels
- * @param string|array $var
- * @return string|array
- */
- public static function sanitize(&$var)
- {
- if(is_array($var)) {
- foreach($var as &$v) {
- self::sanitize($v);
- }
- } else {
- $var = htmlspecialchars($var);
- }
- return $var;
- }
- /**
- * Get final redirect url - prepare url for pass GET data,
- * can be used to make sure about http/https or different languages
- * without redirects.
- *
- * @param string $url - url to check
- * @return string new final url after all inner redirects
- */
- public static function getRedirectUrl ($url)
- {
- stream_context_set_default(array(
- 'http' => array(
- 'method' => 'HEAD'
- )
- ));
- $headers = get_headers($url, 1);
- if ($headers !== false && isset($headers['Location'])) {
- return $headers['Location'];
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement