Re: PHP Browser detection

by "Rythmist" <Rythmist(at)gamewood.net>

 Date:  Wed, 31 May 2000 15:28:02 -0400
 To:  <Reywob(at)aol.com>,
<hwg-languages(at)hwg.org>
 References:  aol
  todo: View Thread, Original
Hi,

The following snippet was taken from the book "PHP Essentials".
(Unfortunately I'm using Php3 on PWS so the preg_match() function generates
a nasty error.)
However, on a unix server it works.

The script will work as is as long as it is the only code in the document.
(No Html at all because the header info can be sent only once. and the
header() function does just that.

<?php

 $browser_type = getenv("HTTP_USER_AGENT");

 if (preg_match("/compatible; MSIE/i", "$browser_type"))


  $location = "http://www.studiodeluxe.net/pws/;

 }else  if (preg_match("/Mozilla/i", "$browser_type")) {

  $location = "http://www.studiodeluxe.net/pws/;

 }else  if (preg_match("/Lynx/i", "$browser_type")) {

  $location = "http://www.studiodeluxe.net/pws/;

 } else {

  $location = "http://www.studiodeluxe.net/shelley/";

 }

 header("Location: $location");
 exit;
?>

Rythmist

----- Original Message -----
From: <Reywob(at)aol.com>
To: <hwg-languages(at)hwg.org>
Sent: Wednesday, May 31, 2000 1:26 PM
Subject: PHP Browser detection


> Hi,
>
> How can I use PHP to display different content depending on what browser
is
> being used?  Is there an in-built function or do I need to do a javascript
> detection first and then somehow use the results?
>
> Thanks,
> Peter
>

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA