Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 11:44 PM   PM User | #1
Sman5109
Regular Coder

 
Join Date: Oct 2006
Posts: 164
Thanks: 5
Thanked 0 Times in 0 Posts
Sman5109 can only hope to improve
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.
Sman5109 is offline   Reply With Quote
Old 09-06-2007, 12:18 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:11 PM.


Advertisement
Log in to turn off these ads.