Sending document information using PHP header or HTML meta http-equiv?

To send HTML document information, such as content-encoding , charset , date , last-modified , etc., we can also use the PHP header() or HTML meta http-equiv <meta http-equiv=... /> . Which is practically better? Can anyone develop the pros and cons of both methods?

I wonder if each of them has the best performance for a particular application (for example, it is better to define charset and the other for content-encoding ?!?

+4
source share
3 answers

Use real HTTP headers

  • HTTP headers take precedence over <meta http-equiv
  • HTTP headers can be used by any HTTP client (and not just those that parse HTML)
  • HTTP headers can be used by clients who make a HEAD request
  • Only a limited set of HTTP headers (by browsers) is supported in <meta http-equiv

There is an argument for including encoding information using a meta element (since this will be saved if the document is saved, and a copy will be available from the file system instead of HTTP).

+4
source

The php function "header ()" sets only the HTTP header: the header function on php.net , this is very useful if you want to attach a PDF document or something like that.

In your case, I would use the usual html meta tags.

+1
source

A compromise with PHP headers is beneficial if you use variables and CSS in correlation with each other, or if for some reason you cannot modify .htaccess to allow custom content types such as vector components, etc.

HTTP and PHP headers, perhaps alone, do the same. One does not have significant utility over another.

+1
source

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


All Articles