PHP Thumb » Help & Bugs » Help

XHTML Strict & phpthumbs

(6 posts)
  1. Glad to see you are compliant ..... however, I have a small problem ....

    Your code wishes to issue


    public function show ()
    {
    if (headers_sent())
    {
    throw new RuntimeException('Cannot show image, headers have already been sent');
    }

    switch ($this->format)
    {
    case 'GIF':
    header('Content-type: image/gif');
    imagegif($this->oldImage);
    break;
    case 'JPG':
    header('Content-type: image/jpeg');
    imagejpeg($this->oldImage, null, $this->options['jpegQuality']);
    break;
    case 'PNG':
    header('Content-type: image/png');
    imagepng($this->oldImage);
    break;
    }

    return $this;
    }

    And my Code for XHTML compliance (and various meta-tags) has already issued this little lot at the start of each page ......

    $charset = "utf-8";
    $mime = "text/html";
    # NOTE: To allow for q-values with one space (text/html; q=0.5),
    # use the following regex:
    # "/text\/html;[\ ]{0,1}q=([0-1]{0,1}\.\d{0,4})/i"
    if((isset($_SERVER["HTTP_ACCEPT"])) && (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml"))) {
    if(preg_match("/application\/xhtml\+xml;q=([0-1]{0,1}\.\d{0,4})/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
    $xhtml_q = $matches[1];
    if(preg_match("/text\/html;q=([0-1]{0,1}\.\d{0,4})/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
    $html_q = $matches[1];
    if((float)$xhtml_q >= (float)$html_q)
    $mime = "application/xhtml+xml";
    }
    }
    else
    $mime = "application/xhtml+xml";
    }
    ?>
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="<?php echo $mime ?>;charset=<?php echo $charset ?>" />
    <!-- The lines below are for CSS - On my sites I have the two classes,
    You may only have media, or you may need one for mobile (cell) phones - add / remove as you wish -->
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="/mgjuddltd/html/mgj.css" />
    <link rel="stylesheet" media="print" type="text/css" href="/mgjuddltd/html/mgj_print.css" />
    <meta name="description" content="hire plant parts, spares engineering services"/>
    <meta name="keywords" content="keys, locks, engine, parts, hire, plant, services, engineering,
    consumables,"/>
    <meta name="copyright" content="M.G. Judd Ltd., 2009. All rights Reserved."/>
    <meta name="no-email-collection" content="http://www.unspam.com/noemailcollection" />

    </head>

    I'm still pretty new to this strict encoding, whilst trying to look after non-xhtml browsers - I'm not too sure how to get around the issuing of a "content-type:" to your specific requirements....

    I'm sorta guessing that most browsers can handle
    jpgs & gifs - w3c has this to say on the matter....

    Attributes of this type identify the allowable content type(s) of an associated URI (usually a value of another attribute on the same element). At its most general, it is a comma-separated list of media ranges with optional accept parameters, as defined in section 14.1 of [RFC2616] as the field value of the accept request header.

    In its simplest case, this is just a media type, such as "image/png" or "application/xml", but it may also contain asterisks, such as "image/*" or "*/*", or lists of acceptable media types, such as "image/png, image/gif, image/jpeg".

    The user agent must combine this list with its own list of acceptable media types by taking the intersection, and then use the resulting list as the field value of the accept request header when requesting the resource using HTTP.

    For instance, if the attribute specifies the value "image/png, image/gif, image/jpeg", but the user agent does not accept images of type "image/gif" then the resultant accept header would contain "image/png, image/jpeg".

    A user agent must imitate similar behavior when using other methods than HTTP. For instance, when accessing files in a local filestore, <p src="logo" srctype="image/png, image/jpeg"> might cause the user agent first to look for a file logo.png, and then for logo.jpg.

    If a value for the content type is not given, "*/*" must be used for its value.

    For the current list of registered content types, please consult [MIMETYPES].

    So, placing a In its simplest case, this is just a media type, such as "image/png" or "application/xml", but it may also contain asterisks, such as "image/*" or "*/*", or lists of acceptable media types, such as "image/png, image/gif, image/jpeg".
    type statement would keep me in alignment with the rules - My question then is, what would be, if any, the effect of removing the code from your library with those directives in ?

    -- Yeah, I know I'm a pain in the ass, but, please try to see it my way - I already have a header section to look after all my pages, and I would be most pleased to be able to adapt to use your fantastic php-code.

    Regards,

    Phill.

    Posted 2 years ago #
  2. Oops ... Sorry, I completely missed out the Error Message ....

    Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot show image, headers have already been sent' in /var/www/webserver/thumb_plugins/GdThumb.inc.php:562 Stack trace: #0 /var/www/webserver/mgjuddltd/html/display_parts.php(25): GdThumb->show() #1 {main} thrown in /var/www/webserver/thumb_plugins/GdThumb.inc.php on line 562

    Line 562, being the part that checks if headers have already been sent..

    Posted 2 years ago #
  3. Yeah, I think you're talking about two completely different things... remember, if PHP is throwing an error regarding headers, this has absolutely nothing to do with the browser.

    Basically what's happening is that you've started output elsewhere in your PHP code, and when the library tries to send headers for the image itself the exception is thrown. This is because PHP has already sent headers to the client, and once that's done you can't send anymore (headers were sent as a result of prior output started).

    Basically, removing this code from my library won't do anything for you... you'll just see essentially the same error thrown, but this time from PHP itself, rather than an exception thrown by the library.

    Hope that helps :)

    Posted 2 years ago #
  4. Yeah, it does help greatly ... the penny has dropped ... As you will see - my header file issues HTML commands - So, I'm guessing, I need your 'require-once' in the php heading part of my 1st header .... if that makes any sense ?

    Thanks for the speedy reply - I'll get my head round this stuff !!

    Phill.

    Posted 2 years ago #
  5. Well, what can I say ? WOW !!! - fantastic, thanks for a brilliant library. The simple solution was to keep the call seperate as PHP module (Just like your example said to)... Ooops ;-)

    Phill.

    Posted 2 years ago #
  6. No problem, thanks for the kind words :) Feel free to post any other issues / concerns / suggestions you may have and enjoy!

    Posted 2 years ago #

RSS feed for this topic

Reply

You must log in to post.