p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Browser type/version: debug code?


Message #1 by Mae Shell <mae@m...> on Wed, 03 Apr 2002 14:19:10 -0500
Hi again everyone! On my quest for a way to test for browser type and
version, I have found a script that seems to do exactly what I want. Once I
get it all working, I'll post it to the list.

According to my logic, the script I've modificed *should* check for two
possible browser type/version combinations. If either is found to be true,
then the user is sent to a different page. If neither is true, than the PHP
page that contains this script (along with HTML content) will go ahead and
load.

Here's my problem. When I run my final "if" test (pasted below), I get a
parse error. (I won't paste the entire script that determines browser type
and version, because it's very long. That part works -- I've tested it.) Any
ideas why?

Thanks,

-Mae

---------------

    [Notes: 
    
    get_browser_version() contains a value such as "5.0"
    
    get_browser_agent() contains either the value "IE", "MOZILLA",
    OPERA" or "OTHER"

    The code is placed before the <HTML> tag in this document
    because of the use of "Header" to redirect the page.]

    -----

    <?php

    //Checks to see if the browser is a version of Internet Explorer
    //below 4.0 and sends to the appropriate page if it is.

    if ( browser_get_version() < "4.0" && browser_get_agent()=="IE" ) {
        header ("Location: [url here]");
    } 


    //Checks to see if the browser is a version of Netscape below 5.0 and
    //sends to the appropriate page if it is.

    if ( browser_get_version() < "5.0" && browser_get_agent()=="MOZILLA" ) {
        header ("Location: "[url here]");
    }

    ?>

    <html>
    <head>

    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

<body bgcolor="#FFFFFF" text="#000000">

Testing

</body>
</html>

Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 3 Apr 2002 11:18:38 -0800
>         header ("Location: "[url here]");

It looks like you're closing your string too early... that's the only
problem I see... although i do have a comment:

by comparing the get_version() value to "4.0" or "5.0", you're forcing PHP
to perform a string to float type conversion on the fly.  You're probably
better off just using the float values and shedding the useless processing
overhead.


take care,

nik

Message #3 by "Krister" <krister@m...> on Wed, 3 Apr 2002 23:37:20 +0200
Hi

header ("Location: "[url here]");  // Check this
header ("Location: [url here]");   // and compare to this (your first if)

Krister

----- Original Message -----
From: "Mae Shell" <mae@m...>
To: "beginning php" <beginning_php@p...>
Sent: Wednesday, April 03, 2002 9:19 PM
Subject: [beginning_php] Browser type/version: debug code?


> Hi again everyone! On my quest for a way to test for browser type and
> version, I have found a script that seems to do exactly what I want. Once
I
> get it all working, I'll post it to the list.
>
> According to my logic, the script I've modificed *should* check for two
> possible browser type/version combinations. If either is found to be true,
> then the user is sent to a different page. If neither is true, than the
PHP
> page that contains this script (along with HTML content) will go ahead and
> load.
>
> Here's my problem. When I run my final "if" test (pasted below), I get a
> parse error. (I won't paste the entire script that determines browser type
> and version, because it's very long. That part works -- I've tested it.)
Any
> ideas why?
>
> Thanks,
>
> -Mae
>
> ---------------
>
>     [Notes:
>
>     get_browser_version() contains a value such as "5.0"
>
>     get_browser_agent() contains either the value "IE", "MOZILLA",
>     OPERA" or "OTHER"
>
>     The code is placed before the <HTML> tag in this document
>     because of the use of "Header" to redirect the page.]
>
>     -----
>
>     <?php
>
>     //Checks to see if the browser is a version of Internet Explorer
>     //below 4.0 and sends to the appropriate page if it is.
>
>     if ( browser_get_version() < "4.0" && browser_get_agent()=="IE" ) {
>         header ("Location: [url here]");
>     }
>
>
>     //Checks to see if the browser is a version of Netscape below 5.0 and
>     //sends to the appropriate page if it is.
>
>     if ( browser_get_version() < "5.0" && browser_get_agent()=="MOZILLA" )
{
>         header ("Location: "[url here]");
>     }
>
>     ?>
>
>     <html>
>     <head>
>
>     <title>Untitled Document</title>
>     <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
>     </head>
>
> <body bgcolor="#FFFFFF" text="#000000">
>
> Testing
>
> </body>
> </html>
>
>


  Return to Index