glasspoole — 2011-06-11T23:27:03-04:00 — #1
i know a little php but now i want to learn more. So i start by making a little static website a little dynamic that its easier to maintain. So that i don't need to change 10 html pages if i want to change something in the header.
So i'm trying to set the variable for the xu-a-compatible mode.
This is a variable?:
$xua = header('X-UA-Compatible: IE=edge,chrome=1');
and i set it above the html doctype.
Than i want to print it in the html head:
<?php print $xua; ?>
But the funny thing is that IE react's even if i don't put the print function in the head. Why is that? I mean the first line is just a variable and should not be seen by the browser???
Oh wait. The header is something the server sends. So there is no need to prind it in the html head. I was thinking the metatag way. So:
<?php header('X-UA-Compatible: IE=edge,chrome=1'); ?>
above the doctype is enough - right?
But i still wonder why is it send if i set it as a variable?
logic_earth — 2011-06-12T01:09:44-04:00 — #2
header() function returns nothing to set to a variable.
Below is the function declaration from the PHP manual, the first word is the return type. Void means it returns nothing.
void [B]header[/B] ( string $string [, bool $replace = true [, int $http_response_code ]] )
Now one thing to know, you do not need this header if your code is standards complaints. You only really need it if its not.
glasspoole — 2011-06-12T01:22:16-04:00 — #3
you need it to turn off the compatible mode switch, to make sure IE always uses standards mode and to tell IE to use Chrome frame if it is installed.
cranial_bore — 2011-06-12T06:07:39-04:00 — #4
PHP's header function has absolutely nothing to do with the HTML <head> section.
I don't know why you need a variable at all, if you want this meta tag in your <head> section. Just put it directly in the HTML its self.
You can use includes to include the same header on multiple pages, but that file could even be absent of any PHP.
If you are needing PHP to echo it for some reason, then the meta tag in question is just a string.
No different to either of these:
echo "How long is a piece of string?";
echo "<!DOCTYPE html>\
glasspoole — 2011-06-12T07:55:58-04:00 — #5
As i wrote: Oh wait. The header is something the server sends. So there is no need to prind it in the html head. I was thinking the metatag way.
Because x-ua was first a meta tag and not send by apache or now by php. So i was first thinking i need to put it in the head section.
logic_earth — 2011-06-12T13:29:25-04:00 — #6
IE 8/9 does so by default. It will run your site in standards mode as long as your site is standards compliant, ie., passes the HTML Validation and does not throw IE into quirks mode which it should not. Otherwise, you do not need it.
glasspoole — 2011-06-13T09:08:04-04:00 — #7
Call it prevention for the normal user. How many user know what the IE compatible mode is and realize if they maybe switched it on? Always make it luser save...
logic_earth — 2011-06-13T12:38:51-04:00 — #8
If the user turned compatibly mode on all the time, then this header is ignored. User choice prevails over the site.
glasspoole — 2011-06-13T13:11:16-04:00 — #9
But that means he/she is not a luser and knows what he/she is doing if they go into the IE options.
logic_earth — 2011-06-13T13:13:43-04:00 — #10
Then you have nothing to worry about because then IE will use the default which is standards mode.
Besides if the user switch compatibility mode on, in any case then it is on and your header is ignored.
The real purpose of the header is to turn compatibility mode on automatically for sites that need it.
glasspoole — 2011-06-13T13:41:48-04:00 — #11
You don't get it. I talk about luser, for example like my parents. People who hit the comp mode button and did not realize that something is switched on that they don't even know what it is.
It just force's IE to use the most up to date rendering engine that it has available.
logic_earth — 2011-06-13T14:42:26-04:00 — #12
No I get it. But if they hit that button turning it on for every single site your header is ignored. The header does not do what you think it does. Its a suggestion not an absolute force this type deal.
IE 8/9 both use the most recent rendering engine they have BY DEFAULT. However, if the user wishes to change that they can, and your header is IGNORED. You cannot force the matter. The user can even chose to run in standard mode on websites that need compatibility mode. Again the header is ignored when overridden by the user.
glasspoole — 2011-06-13T15:05:38-04:00 — #13
It does, because if you send this header the button is not there. If its not there they can't hit it.