Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Redirect Script Depending On User's Browser
CrazyRob
post Sep 22 2006, 03:33 PM
Post #1


ITS ALIVE.....MUHHHAAAA
*********

Group: Members
Posts: 532
Joined: 17-October 05
From: Chippenham UK
Member No.: 13,031



Hi everyone,

oik so there is this design im doing for a new site and the problem is that the site does not display properly in Internet Explorer but it does in firefox. How do i get the site to redirect you to a page that says somthing like "you need to have firefox instalkled to view this page" if you are not running firefox?
Go to the top of the page
 
+Quote Post
AeonLan
post Sep 22 2006, 04:54 PM
Post #2


Member [Level 3]
******

Group: Members
Posts: 96
Joined: 22-September 06
From: In Front of the Monitor
Member No.: 30,404



I thought you might want to look into this. I got this code snippet a long time ago. ^_~

CODE

<?php

function browser_detection( $which_test ) {

    // initialize the variables
    $browser = '';
    $dom_browser = '';

    // set to lower case to avoid errors, check to see if http_user_agent is set
    $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';

    elseif (stristr($navigator_user_agent, "msie 4"))
    {
        $browser = 'msie4';
        $dom_browser = false;
    }

    elseif (stristr($navigator_user_agent, "msie"))
    {
        $browser = 'msie';
        $dom_browser = true;
    }
    
    elseif (stristr($navigator_user_agent, "mozilla/4"))
    {
        $browser = 'ns4';
        $dom_browser = false;
    }
    
    else
    {
        $dom_browser = false;
        $browser = false;
    }

    // return the test result you want
    if ( $which_test == 'browser' )
    {
        return $browser;
    }
    elseif ( $which_test == 'dom' )
    {
        return $dom_browser;
        //  note: $dom_browser is a boolean value, true/false, so you can just test if
        // it's true or not.
    }
}

?>


The above function can be called by:

CODE
$user_browser = browser_detection('browser');

if ( $user_browser == 'opera' )
{
    do something;
}


or you may want:

CODE
if ( browser_detection('dom') )
{
    execute the code for dom browsers
}
else
{
    execute the code for non DOM browsers
}


and so on.......
Go to the top of the page
 
+Quote Post
CrazyRob
post Sep 22 2006, 05:09 PM
Post #3


ITS ALIVE.....MUHHHAAAA
*********

Group: Members
Posts: 532
Joined: 17-October 05
From: Chippenham UK
Member No.: 13,031



ok so how would i put that into my page? would i add it to the top or bottom or in the middle of the page code?

This post has been edited by mxweb: Sep 22 2006, 05:09 PM
Go to the top of the page
 
+Quote Post
AeonLan
post Sep 22 2006, 05:18 PM
Post #4


Member [Level 3]
******

Group: Members
Posts: 96
Joined: 22-September 06
From: In Front of the Monitor
Member No.: 30,404



Declare the function definition inlined with other function definitions of your php page or just simply put it on the top.

As for the usage, you can place the if(...) statement where you would like the script to be executed, like:

CODE

/* Log in and verification or something you want to be executed first */
/* Continue */
/* Then if you want to detect browser now use the browser detection */
/* Sample */
$this_browser = browser_detection('browser');

if($this_browser == 'msie' || $this_browser == 'msie4'){
   // Redirect user
} else {
   // continue loading page
}


happy.gif
Go to the top of the page
 
+Quote Post
CrazyRob
post Sep 22 2006, 05:28 PM
Post #5


ITS ALIVE.....MUHHHAAAA
*********

Group: Members
Posts: 532
Joined: 17-October 05
From: Chippenham UK
Member No.: 13,031



ok im still confused so here is the code
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

<meta name="description" content="Lorem Ipsum" />
<meta name="keywords" content="Lorem Ipsum" />

<meta name="robots" content="index,follow" />

<title>Mx Scripting</title>

<link href="template02.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
<!--
.style2 {
    color: #1c6ea8;
    font-size: 22px;
}
-->
</style>
</head>

<body>
<div id="container">
<div id="header">
<h1>&nbsp;</h1>
</div>
<div id="mainnav">
    <ul>
      <li><a href="#">&nbsp;Contact us </a></li>
      <li><a href="#">clients</a></li>
      <li><a href="#">services</a></li>
      <li><a href="#">Partners</a></li>
      <li><a href="#">FOrums</a></li>
      <li><a href="#">Home</a></li>
      
    </ul>
  </div>


  <div id="mainnavsub">
    <ul><li><a href="#"></a></li>
        <li><a href="#">latest News </a></li>
        <li><a href="#">RSS Feeds </a></li>
        <li><a href="#">Advertise</a></li>
        <li><a href="#">About US </a></li>
    </ul>
  </div>

  <div id="sidebar">
    <h3>Menu</h3>
    <div id="nav-right">
      <ul>
        <li><a href="http://www.mxscripting.net/html/">HTML Scripts </a></li>
        <li><a href="http://www.mxscripting.net/php/">PHP Scripts </a></li>
        <li><a href="http://www.mxscripting.net/asp/">ASP Scripts </a></li>
        <li><a href=""></a></li>
        <li><a href="http://www.mxscripting.net/templates//">Premium Templates </a></li>
        <li><a href="http://www.mxscripting.net/freetemp/">Free Templates </a></li>
    <li><a href="http://www.mxscripting.net/graphics/">Graphics </a></li>
    <li><a href="http://www.mxscripting.net/css/">CSS Style Sheets </a></li>
    <li><a href=""></a></li>
    <li><a href="http://www.mxscripting.net/wtools/>Webmaster tools </a></li>
    <li><a href="http://www.mxscripting.net/validators/">HTML Validators </a></li>
    <li><a href="http://www.mxscripting.net/cssvalid/">CSS Validators </a></li>
      </ul>
    </div>
    <h3>&nbsp;</h3>
    <h3>Advertisment</h3>
    <p class="thumbs">
<a href="index.html"></a><script type="text/javascript"><!--
google_ad_client = "pub-6827643994408753";
google_ad_width = 200;
google_ad_height = 200;
google_ad_format = "200x200_as";
google_ad_type = "image";
google_ad_channel ="";
google_color_border = "282828";
google_color_bg = "282828";
google_color_link = "282828";
google_color_text = "000000";
google_color_url = "1C6EA8";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
    <h3> Forum Installed </h3>
    <p>We have now succesfully re-installed the forum and a new skin is being devloped which should properly blend into the site. </p>
  </div>
    <div id="content">
      <h1>Welcome to Mx Scripting </h1>
      <p>Welcome to Mx Scripting, as you may notice we are currently updating our site so you may notice some major changes. We hope to build a huge and active community like we once had. Untill the main bit of our site is finished why not register on the forums and meet other members of the Mx community. </p>
      <h2>Send us your scripts</h2>
      <p>If you have a script or a link that you think may fit into one of the catogories why not send them to us via the Contact Form we will then reveiw it and who knows your script may show up on this very site. </p>
      <p>&nbsp;</p>
      <p class="style2">Advertise on this site</p>
      <p>If you would like to advertise on this site, please Fill out the Advertise Form which can also be found in the Contact Us area of the site. We opperate our advertising system in cost per impression which when tested was found the be the cheapest option. </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
    </div>
    <p>

<!--
   End Side bar and thumbs
-->

<!--
   Start of footer data
--></p>

    <div id="footer-contents">
      <p id="footer-links"><a href="http://validator.w3.org/check/referer">[XHTML 1.0]</a> <a href="http://jigsaw.w3.org/css-validator/">[CSS]</a></p>
  </div>

<!--
   End of footer data
-->

</div>
</body>
</html>


can you tell me where i can put the code in?

This post has been edited by mxweb: Sep 22 2006, 06:34 PM
Go to the top of the page
 
+Quote Post
AeonLan
post Sep 22 2006, 05:45 PM
Post #6


Member [Level 3]
******

Group: Members
Posts: 96
Joined: 22-September 06
From: In Front of the Monitor
Member No.: 30,404



Oh I see.... What you posted is an HTML file. You need to have a PHP file to run this codes. Does your host support PHP? If yes, make an index.php and put this.. inside

CODE

<?php

global $this_browser;

function browser_detection( $which_test ) {

    // initialize the variables
    global $browser = '';
    global $dom_browser = '';

    // set to lower case to avoid errors, check to see if http_user_agent is set
    $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';

    elseif (stristr($navigator_user_agent, "msie 4"))
    {
        $browser = 'msie4';
        $dom_browser = false;
    }

    elseif (stristr($navigator_user_agent, "msie"))
    {
        $browser = 'msie';
        $dom_browser = true;
    }
    
    elseif (stristr($navigator_user_agent, "mozilla/4"))
    {
        $browser = 'ns4';
        $dom_browser = false;
    }
    
    else
    {
        $dom_browser = false;
        $browser = false;
    }

    // return the test result you want
    if ( $which_test == 'browser' )
    {
        return $browser;
    }
    elseif ( $which_test == 'dom' )
    {
        return $dom_browser;
        //  note: $dom_browser is a boolean value, true/false, so you can just test if
        // it's true or not.
    }
}

//Redirection
$this_browser = browser_detection('browser');

if($this_browser = 'ns4'){
   header("Location: forum/index.php");
   exit();
} else {
   echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
    </head>
    <body>
        <center>
            <h1>Your browser does not support this site</h1>
        </center>
    </body>
</html>';

?>


This post has been edited by AeonLan: Sep 22 2006, 05:55 PM
Go to the top of the page
 
+Quote Post
Saint_Michael
post Sep 22 2006, 05:59 PM
Post #7


$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
*********************

Group: [HOSTED]
Posts: 6,314
Joined: 21-September 04
From: 9r33|\| 399$ 4|\|D 5P4/\/\
Member No.: 1,218
T17 GFX Crew



Although from the conversation I am having with mxweb off the site, his concer is more css related then actualy browser support, in which he would have to create another set of css that goes with the browser that a person is using.

So you need to include in the php css link as well as the browser type, what I suggest is go to pixel2life.com and then search redirect in php and they have some scripts that do what your asking in your post.