Jump to content

[SOLVED] Redirecting my users to diferent page depending on browser!


saigon

Recommended Posts

Hi good pple,i have been bogged by a problem,i have developed a site and i have a specific bug javascript in IE  browser.so i decided i want to redirect the users to a different page that i modified for IE,now i need help on how to redirect.the code i developed is not working at all!!
here

$browser=$_SERVER['HTTP_USER_AGENT'];
if (strrpos($browser,'Firefox'))
{
header('Location: index.html');
}
else (strrpos($browser,'MSIE'))
{
header('Location: unauthor.html'); 
}
What does "not working at all" look like?

Check that there's no html, not even blank lines before that code.  The very top line of the file should be "<?php", followed by that code checking for browser type.
This is how the code looks like and when i run it on both browsers IE and Firefox!it will will open unauthor.php in both browsers,is there any way to redirect depending on the browser??
please help me.

<?php
$browser=$_SERVER['HTTP_USER_AGENT'];
if (strrpos($browser,'Firefox')) header('Location: unauthor.php');
if (strrpos($browser,'MSIE')) header('Location: index.html');

?>
Aha, you are using strrpos().  That probably doesn't do what you expect.  Use strpos() instead (only one r).

Also, check [code=php:0]if (strpos($browser, 'Firefox') !== false)[/code]


Otherwise the test will fail is Firefox is found at position 0.
Thanx alot man,
Well this is the code u have given me

$browser=$_SERVER['HTTP_USER_AGENT'];
if (strpos($browser,'Firefox')!==false)
{ header('Location: index.html');}
else
{
header('Location: unauthor.html');
}

it is working for Firefox perfectly so for e.g if the browser is firefox it will redirect to index.html but the problme is still with IE.it doesnt redirect to unauthor.html wen i run on IE.I don know wats the problem now!Coz it definately should divert to unauthor.html if the browser is not firefox! yah?
[code]
<?
function get_mybrowser(){
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')){
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) return 'netscape';
  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) return 'firefox';
  else return 'mozilla';
}elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) return 'opera';
  else return 'ie';
}else return 'other';
}

switch(get_mybrowser()){
default: header('Location: unauthor.php'); break;
case "ie": header('Location: unauthor.php'); break;
}
?>
[/code]
Thanx guyz!am finally solved out,it is working properly and my users can get appropriate pages to fit their needs.Thanx alot to bther and taith.Am grateful u two.Thanx alot again.if there is anyday u myt need my consultancy don hesitate to buzz me,mi email is [email protected]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.