SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Beginning php. Variable does not work how it should?

    Hi,

    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?:
    PHP Code:
    <?php
    $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 Code:
    <?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???

    EDIT:
    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 Code:
    <?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?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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 header ( 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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    PHP Code:
    echo "How long is a piece of string?";
    echo 
    "<!DOCTYPE html>\n"

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Glasspoole View Post
    you need it to turn off the compatible mode switch, to make sure IE always uses standards mode
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    If the user turned compatibly mode on all the time, then this header is ignored. User choice prevails over the site.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But that means he/she is not a luser and knows what he/she is doing if they go into the IE options.

  10. #10
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  11. #11
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  12. #12
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Glasspoole View Post
    You don't get it.
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  13. #13
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It does, because if you send this header the button is not there. If its not there they can't hit it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •