In reply to this blog post:

Definitely is not possible with my salary, I prefer to stick with emulators and leave the final testing (when I’m pretty confident that everything will work) with friends & colleagues.

Obviously it’s not the same as having a test lab at your disposal, but you are leaving apart freelancers and low budget developers, plus, it’s as insane as asking a developer to test something with every browser, every possible OS, and many different PCs from an old Pentium MMX w/ 800×600 CRT monitor to a brand new Core i7 Extreme w/ 2560×1600 monitor.

We are in an era of cross-browser compatibility, where standards are here to make our lives easier and browser vendors are releasing updates more often than ever in both, desktop and mobile, and specially, trying to be as close as possible to recommended & stable standards.

It’s a fact that standards are an utopia, there will always be a browser which will render something (or everything) wrong, there will always be a browser which will become unstable by no apparent reason, but that doesn’t mean you have to address all those issues, specially if they don’t belong to yourself, you can do it if you want, but it’s not really needed, especially if it’s an update-able platform which is likely to get an update for that specific browser, otherwise the IE6 Nightmare will never end.

I believe it’s better to combine bleeding edge with old techniques, such as having a content negotiator with a modern HTML5/CSS3 version + responsive design for whitelisted browsers, and a 90′s-like version with basic HTML, no JS and the most elementary CSS such as font-family & font-size for the rest of browsers. Obviously with a way for users to switch between them, and a way to track all your pages in a single place which browsers register more version switches to help you whitelist newer compatible browsers. Sounds overkill? Testing in current + outdated phones & the typical IE7-10 + FF 3.6 + FF + Chrome + Opera + Safari stack is even worse!

I know that user agent sniffing is blasphemy, but it’s also blasphemy to believe that standards will work by 100% in every known platform, that will never happen, so no matter if it sounds drastic, its way better to display a 90′s-like webpage to incompatible devices/browsers than a broken webpage or even worse, no webpage at all. On the other side, with a basic HTML version you make people’s life easier, because even the least expected to work browser will work.

 

In the PHP documentation you can find http_parse_headers, which requires the PECL HTTP module.

If you can’t install the PECL module you can find some alternatives to replace it in the comments within PHP documentation. I took one left by an Anonymous coder, fixed some bugs it had and extend it to also return parsed Request and Status Lines using the field names defined under RFC2616.

Hope you find it useful, since I’m really creative with names I called this baby http_parse_headers2, pretty original huh?

/**
 * Parses HTTP headers and request/status lines into an associative array.
 *
 * @author  Anonymous
 * @author  Aldo Fregoso C.

 * @license Public Domain
 *
 * @param string $header string containing HTTP headers.
 *
 * @return array Parsed headers with request/status lines using RFC2616's field names.
 */
function http_parse_headers2( $header )
{
    $retVal = array ();
    $fields = explode( "\r\n", preg_replace( '/\x0D\x0A[\x09\x20]+/', ' ', $header ) );
    foreach ( $fields as $field )
    {
        if ( preg_match( '/([^:]+):(.+)/m', $field, $match ) )
        {
            $match[1] = preg_replace( '/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower( trim( $match[1] ) ) );
            $match[2] = trim( $match[2] );

            if ( isset($retVal[$match[1]]) )
            {
                if ( is_array( $retVal[$match[1]] ) )
                {
                    $retVal[$match[1]][] = $match[2];
                }
                else
                {
                    $retVal[$match[1]] = array ( $retVal[$match[1]], $match[2] );
                }
            }
            else
            {
                $retVal[$match[1]] = $match[2];
            }
        }
        else if ( preg_match( '/([A-Za-z]+) (.*) HTTP\/([\d.]+)/', $field, $match ) )
        {
            $retVal["Request-Line"] = array (
                "Method"       => $match[1],
                "Request-URI"  => $match[2],
                "HTTP-Version" => $match[3]
            );
        }
        else if ( preg_match( '/HTTP\/([\d.]+) (\d+) (.*)/', $field, $match ) )
        {
            $retVal["Status-Line"] = array (
                "HTTP-Version"  => $match[1],
                "Status-Code"   => $match[2],
                "Reason-Phrase" => $match[3]
            );
        }
    }
    return $retVal;
}
© 2011 Aldo.MX Suffusion theme by Sayontan Sinha