Jump to content
xisto Community
Sign in to follow this  
CrazyRob

Redirect Script Depending On User's Browser

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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

<?phpfunction 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:

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

or you may want:

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

and so on.......

Share this post


Link to post
Share on other sites

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:

/* 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}

:)

Share this post


Link to post
Share on other sites

ok im still confused so here is the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://forums.xisto.com/no_longer_exists/ xmlns="http://forums.xisto.com/no_longer_exists/; 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> </h1> </div> <div id="mainnav">	<ul>	  <li><a href="#"> 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://forums.xisto.com/no_longer_exists/ Scripts </a></li>		<li><a href="http://forums.xisto.com/no_longer_exists/ Scripts </a></li>		<li><a href="http://forums.xisto.com/no_longer_exists/ Scripts </a></li>		<li><a href=""></a></li>		<li><a href="http://forums.xisto.com/no_longer_exists/ Templates </a></li>		<li><a href="http://forums.xisto.com/no_longer_exists/ Templates </a></li>	<li><a href="http://forums.xisto.com/no_longer_exists/ </a></li>	<li><a href="http://forums.xisto.com/no_longer_exists/ Style Sheets </a></li>	<li><a href=""></a></li>	<li><a href="http://forums.xisto.com/no_longer_exists/ tools </a></li>	<li><a href="http://forums.xisto.com/no_longer_exists/ Validators </a></li>	<li><a href="http://forums.xisto.com/no_longer_exists/ Validators </a></li>	  </ul>	</div>	<h3> </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> </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> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </p>	  <p> </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?
Edited by mxweb (see edit history)

Share this post


Link to post
Share on other sites

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

<?phpglobal $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://forums.xisto.com/no_longer_exists/;	<head>	</head>	<body>		<center>			<h1>Your browser does not support this site</h1>		</center>	</body></html>';?>

Edited by AeonLan (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I see. Third-party scripts are more preferred as they have been tested many times and continuous maybe available. :)Well ~Happy Coding.

Share this post


Link to post
Share on other sites

Nicely done. Good job.^_~Remember, even if you have solved the problem, try to think of better solutions to that problem. Until Satisfaction is met.

Share this post


Link to post
Share on other sites

Although I know the truth about what really happen I won't mention it because I'm a nice guy and won't destroy a designer like that.[hide=option]he left 2 links blank and so it messed up the layout and gave an extra space in ie but not in FF. TISK TISK...Ok I lied im Evil I can't help it :):)[/hide]on a side note the problem was fixed initially so if anyone else has problems I will keep this open.

Share this post


Link to post
Share on other sites

LMAO!!!! ~Don't click the show/hide mxweb... XXDLesson to be learned: Analyze codes line by line before asking for help . :)

Share this post


Link to post
Share on other sites

MXweb (and Others, too),One way to handle the IE css problems is to create a second css file and use this sample of HTML to direct the user's Browser to implement the second CSS file if they are in fact using IE. I find it simpler to do this than to have a whole whack of hacks for the different IE (and other) Browsers.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><html lang="en"><head>  <title>Purcell Crossing Consultants Group :  Page: </title>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" >  <meta name="expires" content="0" >  <meta name="description" content=" A description of the pccg site needs to be included here." >  <style type="text/css" media="screen">@import "./fixed4all.css";  </style>       <!--[if IE]> <link  href="./fixed4ie.css"  rel="stylesheet"  type="text/css"  media="screen"> <script type="text/javascript">onload = function() { content.focus() }</script><![endif]--></head>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.