saigon Posted December 20, 2006 Share Posted December 20, 2006 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'); } Quote Link to comment Share on other sites More sharing options...
btherl Posted December 20, 2006 Share Posted December 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
saigon Posted December 20, 2006 Author Share Posted December 20, 2006 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');?> Quote Link to comment Share on other sites More sharing options...
btherl Posted December 20, 2006 Share Posted December 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
saigon Posted December 20, 2006 Author Share Posted December 20, 2006 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? Quote Link to comment Share on other sites More sharing options...
taith Posted December 20, 2006 Share Posted December 20, 2006 [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] Quote Link to comment Share on other sites More sharing options...
saigon Posted December 20, 2006 Author Share Posted December 20, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.