-1

in my web server all pages i develop targeting internet explorer browser but other browser can open it but not view properly.therefore i need to forcefully open it in internet explorer.if user open it in other browser than IE it gives a message box saying "The site is best viewed using Microsoft Internet Explorer version 5 or above" and site is open in that browser.But i need to redirect the site to IE browser and close other browser window.

how can i achieve this altering blow code.

this is my 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'] ) : '';

	// run through the main browser possibilities, assign them to the main $browser variable
	if (stristr($navigator_user_agent, "opera")) 
	{
		$browser = 'opera';
		$dom_browser = true;
	}

	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, "konqueror")) || (stristr($navigator_user_agent, "safari"))) 
	{
		$browser = 'safari'; 
		$dom_browser = true;
	}

	elseif (stristr($navigator_user_agent, "gecko")) 
	{
		$browser = 'mozilla';
		$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.
	}
}


$user_browser = browser_detection('browser');

if ( $user_browser != 'msie' )
{
	echo "<script>alert('The site is best viewed using Microsoft Internet Explorer version 5 or above')
	
	location = 'index.php'
	</script>"; 

	
exit();
} else {
header("location:" . 'index.php');
} 

?>

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Troy III
0

You can detect the browser in use and display the message. You can even have it hide the page content unless the browser used is Internet Explorer. However, there's no way to use JavaScript (or any other web dev. code) to open a completely separate program.

If you are really determined, you might try looking into something that indirectly opens another program through an object or applet of some kind, like flash or Java applets. I don't think you'll find anything, though.

If this were possible, it would be a security problem. Consider the situation if IE had a known exploit and it were possible to force a page to open in IE regardless of the browser it was originally opened in.

I recommend fixing your site. It's not that difficult to develop pages that work everywhere. If I develop pages in accordance with the W3C recommendations, they work pretty well in Firefox, Safari, Opera, and Chrome. Then it's not too difficult to tweak them to work in IE. I've found that doing it the other way around, targeting IE first then tweaking it to work in other browsers, is much more difficult. Pages that require Microsoft ActiveX plugins are an exception of course, but I think it's well worth the time to find an alternative.

--
-- Ghodmode

0

in my web server all pages i develop targeting internet explorer browser but other browser can open it but not view properly.therefore i need to forcefully open it in internet explorer.if user open it in other browser than IE it gives a message box saying "The site is best viewed using Microsoft Internet Explorer version 5 or above" and site is open in that browser.But i need to redirect the site to IE browser and close other browser window.

This is something you shouldn't be able to do!
The one and the best way to handle this situation - is to tell the client that his UA is not capable of rendering those pages correctly or that will fail to retrieve the requested content completely. And of course instuct them how to access that content.
No aplication should be able to run other appications without user live input and action. Not now, and not in future!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.