<?php 
/**
* 
*/
class Input
{
    function get($index = NULL, $xss_clean = FALSE)
    {
        if($index == NULL AND !empty($_GET))
        {
            $get = array();
            foreach (array_keys($_GET) as $key)
            {
                $get[$key] = '';
            }
            return $get;
        }
    }

    function post($index=NULL, $xss_clean=FALSE)
    {
        if($index==NULL AND !empty($_POST))
        {
            $post = array();
            foreach (array_keys($_POST) as $key)
            {
                $post[$key] = '';
            }
            return $post;
        }
    }

    function set_cookie($name = '', $value='', $expire='', $domain='', $path='/', $prefix='', $secure=FALSE)
    {
        foreach (array('value', 'expire', 'domain', 'path','prefix', 'secure', 'name') as $item)
        {
            if(isset($name[$item]))
            {
                $$item = $name[$item];
            }
        }
        if(!is_numeric($expire))
        {
            $expire = time()-86500;
        }
        else
        {
            $expire = ($expire>0)?time()+$expire:0;
        }

        setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
    }
    
    function ip_address()
    {
        if($this->ip_address != FALSE)
        {
            return $this->ip_address;
        }
        $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies)?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];

        $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];

        $this->ip_address = $_SERVER['REMOTE_ADDR'];

        $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];

        $this->ip_address = '0.0.0.0';

        if(strpos($this->ip_address, ',')!=FALSE)
        {
            $x = explode(',', $this->ip_address);
            $this->ip_address = trim(end($x));
        }

        $this->user_agent = (!isset($_SERVER['HTTP_USER_AGENT']))?FALSE:$_SERVER['HTTP_USER_AGENT'];

        $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);

        if(get_magic_quotes_gpc())
        {
            $str = stripslashes($str);
        }
    }

    public function request_headers($xss_clean = FALSE)
    {
        if(function_exists('apache_request_headers'))
        {
            $headers = apache_request_headers();
        }
        else
        {
            $headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE']))?$_SERVER['CONTENT_TYPE']:@getenv('CONTENT_TYPE');

            foreach ($_SERVER as $key => $val)
            {
                if (strncmp($key, 'HTTP_', 5) === 0)
                {
                    $headers[substr($key, 5)] = '';
                }

            }
            foreach ($headers as $key => $val) {
                $key = str_replace('_', ' ', strtolower($key));
                $key = str_replace(' ', '-', ucwords($key));

                $this->headers[$key] = $val;
            }
        }
    }

    public function is_ajax_request()
    {
        return ($_SERVER['HTTP_X_REQUESTED_WITH']) === 'XMLHttpRequest');
    }
}