/ Published in: PHP
Feel free to use this class however you'd like
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class HttpReq { public $param; // the returned POST/GET values public $cookie; // the returned COOKIE values public $session; // the returned SESSION values private $strength; // the strength of sanitization /** * Class constructor takes one argument to set the strength of sanitization * @param string $strength values can be 'normal', 'strong', or 'strict' */ public function __construct($strength='normal'){ $this->strength = $strength; } /** * Method to set, clean &/or sanitize a $_GET value if set * @param string $name the name of the value sought * @param boolean $urlDecode set to TRUE if the method should urldecode the value * @param boolean $san set to TRUE if the method should sanitize the value against XSS vulnerabilities * @return array */ public function by_get($name='', $urlDecode=FALSE, $san=FALSE) { { if ($urlDecode && $san) { $this->param[$name] = $this->clean_data( $this->san_data($_GET[$name]), TRUE); } elseif ($urlDecode) { $this->param[$name] = $this->clean_data($_GET[$name], TRUE); } elseif ($san) { $this->param[$name] = $this->clean_data( $this->san_data($_GET[$name]), FALSE); } else { $this->param[$name] = $this->clean_data($_GET[$name], FALSE); } } else { $this->param[$name] = NULL; } return $this->param; } /** * Method to set, clean &/or sanitize a $_POST value if set * @param string $name the name of the value sought * @param boolean $urlDecode set to TRUE if the method should urldecode the value * @param boolean $san set to TRUE if the method should sanitize the value against XSS vulnerabilities * @return array */ public function by_post($name='', $urlDecode=FALSE, $san=FALSE) { { if ($urlDecode && $san) { $this->param[$name] = $this->clean_data( $this->san_data($_POST[$name]), TRUE); } elseif ($urlDecode) { $this->param[$name] = $this->clean_data($_POST[$name], TRUE); } elseif ($san) { $this->param[$name] = $this->clean_data( $this->san_data($_POST[$name]), FALSE); } else { $this->param[$name] = $this->clean_data($_POST[$name], FALSE); } } else { $this->param[$name] = NULL; } return $this->param; } /** * Additional method to set a $_COOKIE value if set * @param string $name the name of the value sought */ public function by_cookie($name='') { $_COOKIE[$name] : NULL; return $this->cookie; } /** * Additional method to set a $_SESSION value if set * @param string $name the name of the value sought */ public function by_session($name='') { $_SESSION[$name] : NULL; return $this->session; } /** * Private method to clean data * @param mixed $data * @param Boolean $isUrlEncoded */ private function clean_data($data, $isUrlEncoded=FALSE) { return ($isUrlEncoded) ? } /** * Private method to sanitize data * @param mixed $data */ private function san_data($data) { switch($this->strength){ default: break; case 'strong': break; case 'strict': break; } } }
URL: http://www.six-degrees.com/six-degrees.html