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'); 
}
Link to comment
Share on other sites

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');

?>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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 aowino@gmail.com
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.