hello im having twoo issues as stated in the topic name. one of them being the page not being able to load in Opera and the second one being a warning that pops up on the page if you are using IE because my website is Standards Compliant and is not viewable by anyone who uses IE. i have posted the php code below anyone think they can help me out here?

<?php
  $UA = $_SERVER['HTTP_USER_AGENT'];
  if ((!preg_match('#(opera)#si', $UA)) && (!preg_match('#(firefox)#si', $UA)) && (!preg_match('#(safari)#si', $UA)))
  {
  # IE stuff
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- P: Annotated. Read. Learn. Never ever blight the world with tables and inline styles again. -->
<html>
  <head>
		<title>GET LOST IE!</title>
		<meta name="description" content="Official Website of The Underground NJ Student Ministries" />
		<link rel="stylesheet" type="text/css" href="chrometheme/chromestyle2.css" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="chromejs/chrome.js" />
  </head>
	<body>
    <p>Warning, warning your browser SUCKS! get Firefox, Opera or Safari if you want to see this page</p>
	</body>
</html>
<?php
  die();
  }
  # End of IE stuff

  # Do not mess with this, for F and everything else good.

  echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>

after talking with my web host and showing him the php code he said theres nothing wrong with it in the sense of why the IE message doesnt show. so i shall post in the html area of this board as i put it through the w3c validator and its now only tenatively validated. so something in the html is causing it not to show the warning. so now the only thing i need you guys to figure out why it wont load in Opera. thanks! :)

There may be a couple of things wrong here. If you are sending the page out with the correct MIME type for XHTML, ie application/xhtml+xml, then ie will most likely choke on it anyway.

You are also doing yourself and your users an injustice by checking browser capability based on the UA string, as it is very easy and almost common practice to spoof the UA from some browsers. Opera in particular makes it very easy to switch the UA string it sends, so it can be identified as Opera, Mozilla or IE as required. A much safer bet is to test the HTTP_ACCEPT string sent out by the browser. This will accurately determine whether it is capable of accepting and handling correctly formed XHTML documents. IE currently, and for the forseeable future, does not accept application/xhtml+xml documents, so a standard content negotiation include should sort your probelms with both browsers. A sample is included below:

<?php
$charset = "utf-8";//"iso-8859-1";
$mime = "text/html";
function fix_code($buffer) {
return (preg_replace("!\s*/>!", ">", $buffer));
}
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
  if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
	$xhtml_q = $matches[1];
	if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
	  $html_q = $matches[1];
	  if((float)$xhtml_q >= (float)$html_q) {
		$mime = "application/xhtml+xml";
	  }
	}
  } else {
	$mime = "application/xhtml+xml";
  }
}
if($mime == "application/xhtml+xml") {
  $prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
  $meta_content = "<meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\"/>\n";
} else {
  ob_start("xml2html");
  $prolog_type = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"en\">\n";
  $meta_content = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n";
}
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
?>

Simply include this snippet at the very start of each output page to correctly serve text/html or application/xhtml+xml documents as required. A little adjustment should give you the ability to display your warning message as required.

This article has been dead for over six months. Start a new discussion instead.