Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Posts
    164
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Two scripts, same results?

    Hello,

    I dont not know much of any php, i only know a few functions.

    I have this script that i got a while ago:

    PHP Code:
    <?php
    if(eregi(basename(__FILE__),$_SERVER['REQUEST_URI']))
    die(
    'You cannot access this file directly.');
    function 
    set_header()
    {

       
    $charset "utf-8";
       
    $mime "text/html";

       if(
    stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
           if(
    preg_match("/application\/xhtml\+xml;q=0(\.[1-9]+)/i",
                                
    $_SERVER["HTTP_ACCEPT"], $matches)) {
                
    $xhtml_q $matches[1];
                if(
    preg_match("/text\/html;q=0(\.[1-9]+)/i",
                                     
    $_SERVER["HTTP_ACCEPT"], $matches)) {
                    
    $html_q $matches[1];
                    if(
    $xhtml_q >= $html_q) {
                         
    $mime "application/xhtml+xml";
                        }
                }
           } else {
                
    $mime "application/xhtml+xml";
           }
       }
       
    header("Content-Type: $mime;charset=$charset");
       
    header("Vary: Accept");
        if (
    stristr($_SERVER[HTTP_ACCEPT], "application/xhtml+xml")) 
            
    header("Content-Type: application/xhtml+xml; charset=utf-8");
        else
            
    header("Content-Type: text/html; charset=utf-8");
    }
    ?>
    And i just found this one posted somewhere in 2003:
    PHP Code:
    <?php
    if ((isset($_SERVER["HTTP_ACCEPT"]) and
    stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) or
    stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator") )
    {
    header("Content-type: application/xhtml+xml");
    print(
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    }
    else
    {
    header("Content-type: text/html; charset=utf-8");
    }
    ?>
    The first one is a bit more complex and longer and the 2nd is simple and shorter, but the results are about the same (except for the 2nd one it prints the xml line and tells the w3c validator what to see). What does the first one do because of all the lines that the 2nd one doesn't do?

    BTW: the scripts add the application/xhtml+xml mime to supported browsers.

    Thank You.
    Not much, but its something.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    The first one is overkill, and the second one is simplicity defined.
    The first one will not allow you to view the file in a browser, it's designed to be included in all of your pages that need it. The function is really not necessary.


  •  

    Posting Permissions

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