Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This handles my URL vars on almost all of my projects that don't require frameworks.

    //sanitize and return url vars
    function get($fields) {
        if(is_array($fields)) {
            $info = array();
    
            foreach($fields as $field) {
                if(get($field) !== false) {
                    $info[$field] = get($field);
                }
            }
        
            return $info;
        } else {
            //Single Value
            $field = $fields;
        
            if(isset($_POST[$field])) {
                return trim(addslashes(strip_tags($_POST[$field])));
            }
        }
    
        return false;
    }
And this one has been with me since the first time I had to look up all these details:

    function json_header() {
        header("Expires:" . gmdate( "D, d M Y H:i:s", strtotime("+2 minutes")) . "GMT"); 
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT"); 
        header("Cache-Control: no-cache, must-revalidate" ); 
        header("Pragma: no-cache" );
        header("Content-type: application/json");
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: