Welcome Guest, Not a member yet? Register   Sign In
Serving with different mime types
#1

[eluser]Clooner[/eluser]
I want to serve my application with a different mime type then normally I would use a php code similair. This is how I would do it normally.
Code:
header("Vary: Accept");
if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml"))
    header("Content-Type: application/xhtml+xml; charset=utf-8");
else
    header("Content-Type: text/html; charset=utf-8");
or I could also set it with apache and the extensions.

My question is: Is there a way with codeigniter config to set a different or default mime-type which is not text/html?
#2

[eluser]alexsancho[/eluser]
I address the same issue, and finally solves it extending Output class,

Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Output extends CI_Output
{
    var $json;
    var $xhtml = false;
    var $mime = 'text/html';
    
    function MY_Output()
    {
        parent::CI_Output();
    $this->_mimeType();
    }

    function _mimeType()
    {
        if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') || strstr($_SERVER['HTTP_USER_AGENT'], 'WDG_SiteValidator') || strstr($_SERVER['HTTP_USER_AGENT'], 'W3C-checklink') || strstr($_SERVER['HTTP_USER_AGENT'], 'Web-Sniffer') || strstr($_SERVER['HTTP_USER_AGENT'], 'FeedValidator') || strstr($_SERVER['HTTP_USER_AGENT'], 'Poodle predictor') || strstr($_SERVER['HTTP_USER_AGENT'], 'Leknor.com gzip tester')) {
        $this->mime = 'application/xhtml+xml';
        $this->xhtml = true;
    } else {
        if(isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) {
        if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i", $_SERVER['HTTP_ACCEPT'], $matches)) {
            $xhtml_q = $matches[1];
            if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i", $_SERVER['HTTP_ACCEPT'], $matches)) {
            $html_q = $matches[1];
                if((float)$xhtml_q >= (float)$html_q) {
                $this->mime = 'application/xhtml+xml';
                $this->xhtml = true;
            }
            }
        } else {
            $this->mime = 'application/xhtml+xml';
            $this->xhtml = true;
        }
        }
    }
        $this->set_header("Content-type: ".$this->mime."; charset=UTF-8");
    }
}

Regards
#3

[eluser]Clooner[/eluser]
Hi Alex,

thanks for your reply. I know it is a bit late. I was browsing the forums and somehow I didn't even thank you for solving a problem of mine!

This solution works great.




Theme © iAndrew 2016 - Forum software by © MyBB