Learn PHPBB3 to respond to HTTP_IF_MODIFIED_SINCE

    In general, I never googled why bb3 does not respond to the HTTP_IF_MODIFIED_SINCE request and does not give the Last-Modified header.
    And search engines love this business, because the page processing time is sometimes reduced by several times (no need to verify the content).
    After studying the problem and digging in the code, a solution has matured.
    Finish by yourself.

    In the functions.php file, in the area of ​​the line

    header('Pragma: no-cache');

    below, insert:

    $ pchanged = 0;
    if ($ topic_id <1)
    {
    if ($ forum_id> 0)
    {
    $ sql = 'SELECT forum_last_post_time
    FROM'. FORUMS_TABLE. '
    WHERE forum_id ='. $ Forum_id;
    $ result = $ db-> sql_query_limit ($ sql, 1, 0, 600);
    $ pchanged = $ db-> sql_fetchfield ('forum_last_post_time');
    $ db-> sql_freeresult ($ result);
    } else
    {
    $ sql = 'SELECT MAX (forum_last_post_time) as forum_last_post_time
    FROM'. FORUMS_TABLE;
    $ result = $ db-> sql_query_limit ($ sql, 1, 0, 600);
    $ pchanged = $ db-> sql_fetchfield ('forum_last_post_time');
    $ db-> sql_freeresult ($ result);
    }
    } else
    {
    $ sql = '
    FROM '. TOPICS_TABLE. '
    WHERE forum_id ='. $ Forum_id. 'and topic_id ='. $ topic_id;
    $ result = $ db-> sql_query_limit ($ sql, 1, 0, 600);
    $ pchanged = $ db-> sql_fetchfield ('topic_last_post_time');
    $ db-> sql_freeresult ($ result);
    }

    $ if_modified_since = isset ($ _ SERVER ["HTTP_IF_MODIFIED_SINCE"])? preg_replace ('/;.*$/', '', $ _SERVER ["HTTP_IF_MODIFIED_SINCE"]): '';
    $ gmdate_mod = gmdate ('D, d MYH: i: s', $ pchanged). 'GMT';
    if ($ if_modified_since> = $ gmdate_mod) {
    header ("HTTP / 1.0 304 Not Modified");
    exit
    }
    header ("Last-Modified: $ gmdate_mod");


    The code is dirty, you can optimize it - it is to your taste. And so it works.
    If the forum id is not specified in the url (1st page) - the last post time in the forum in general is taken.
    If a topic is specified, then the time of the last post of this topic is taken.
    You can still file a check of the current page of the topic, etc. ... Who will finish - unsubscribe pls. ;)

    Also popular now: