⬆️ ⬇️

Learn PHPBB3 to respond to HTTP_IF_MODIFIED_SINCE

In general, I never google 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 compare content).

After studying the problem and digging into the code, the solution has matured.

Finish yourself.



In the functions.php file, around the line



header('Pragma: no-cache');



Insert below:



$ 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 = 'SELECT topic_last_post_time

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, and it can be optimized - this is to your taste. And so it works.

If the forum id is not specified in the URL (1st page) - the last time the forum is posted in general is taken.

If a topic is specified, then the time of the last post of this topic is taken.

You can also check the current page of the topic, and so on ... Who will finish - post pls. ;)

Source: https://habr.com/ru/post/171873/



All Articles