...

View Full Version : Two scripts, same results?



Sman5109
09-06-2007, 12:44 AM
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
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
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.

Inigoesdr
09-06-2007, 01:18 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum