Chrome is the browser I use, I have it set up so that the script detects safari and chrome as separate entities. When I browse to it, it shows: You are using Windows XP with a Chrome Web Browserwith a Safari Web Browser now I know stristr() is a case-insensitive version of strstr(), which will find the first form of a word in a string. The problem is that when I use it, the rest of the script doesn't work... it goes to the part as if nothing is there, and shows the text on the bottom. I can't figure out why. Can someone help me, is there a chrome/safari level of priority or am I just missing something? <?php //Booleans to set OS and Browser to False. $os = false; $browser = false; //Booleans for Web Browser & OS Functions. $xp = xp(); $vista = vista(); $win7 = win7(); $ubuntu = ubuntu(); $chrome = chrome(); $safari = safari(); $firefox = firefox(); $ie9 = ie9(); $ie8 = ie8(); //Operating Systems function xp(){return(preg_match("/Windows NT 5.1/", $_SERVER['HTTP_USER_AGENT']));} function vista(){return(preg_match("/Windows NT 6.0/", $_SERVER['HTTP_USER_AGENT']));} function win7(){return(preg_match("/Windows NT 6.1/", $_SERVER['HTTP_USER_AGENT']));} function ubuntu(){return(preg_match("/Ubuntu/", $_SERVER['HTTP_USER_AGENT']));} //Web Browsers function chrome(){return(preg_match("/Chrome/", $_SERVER['HTTP_USER_AGENT']));} function safari(){return(preg_match("/Safari/", $_SERVER['HTTP_USER_AGENT']));} function firefox(){return(preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT']));} function ie9(){return(preg_match("/MSIE 9.0/", $_SERVER['HTTP_USER_AGENT']));} function ie8(){return(preg_match("/MSIE 8.0/", $_SERVER['HTTP_USER_AGENT']));} // If you have one of the valid Operating System. if($ubuntu){echo 'You are using Ubuntu Operating System ';} if($xp){echo 'You are using Windows XP ';} if($vista){echo 'You are using Windows Vista Operating System ';} if($win7){echo 'You are using Windows 7 Operating System ';} // If you have one of the valid Web Browser. if($chrome){echo 'with a Chrome Web Browser';} if($firefox){echo 'with an Firefox Web Browser';} if($safari){echo 'with a Safari Web Browser';} if($ie8){echo 'with an Internet Explorer 8 Web Browser';} if($ie9){echo 'with an Internet Explorer 9 Web Browser';} //If OS or Browser not found in list. if ($ubuntu || $xp || $vista || $win7) $os = true; if($firefox || $chrome || $safari || $ie9 || $ie8) $browser = true; if(!$browser || !$os){ echo'<strong>'; echo '<br />' . $_SERVER['HTTP_USER_AGENT'] . '<br /><br />Administrator someone in your work force is using an unsupported browser or OS, please email this information to the developer of the NCMR software you are using. It will allow your browser/OS combination to be used correctly. Sorry for the inconvenience.</strong> <br /><br />Please copy and paste the text above and send it to your web administrator. It will explain everything he/she needs to do.<br />';} ?> Code (markup):
The User Agent string in Chrome includes the word "Safari". To differentiate them, you'll want to use 'else if' in your list of 'if' statements so that once a match is found, the rest of the tests won't be tried. You'll probably have to experiment a bit to get it right, but it shouldn't be too hard. Good luck!
Not really a possibility... the program I'm designing will utilize the different browsers and OS systems to produce a specific format for not only a website, but also the CSS that it uses. I need to have the script show Safari and Chrome separately. Hence why I asked how to use the stristr()command in this situation.
Wouldn't something like this work? function safari(){return(preg_match("/Safari/", $_SERVER['HTTP_USER_AGENT']));} function chrome(){ return(preg_match("/Chrome/", $_SERVER['HTTP_USER_AGENT']) && !safari());} PHP: The problem as I got it is that both Safari and Chrome have a "Chrome" string on the user-agent information. But Chrome doesn't have "Safari" on its user-agent information, am I right?
Yup, you are right, but the string you suggested will remove the Chrome attribute all together, because safari is in the chrome attribute...
Solved it. <?php //Booleans to set OS and Browser to False. $os = false; $browser = false; //Booleans for Web Browser & OS Functions. $info = $_SERVER['HTTP_USER_AGENT']; $xp = 'Windows NT 5.1'; $vista = 'Windows NT 6.0'; $win7 = 'Windows NT 6.1'; $ubuntu = 'Ubuntu'; $ie9 = 'ie9'; $ie8 = 'ie8'; $chrome = '/Chrome/'; $safari = '/Safari/'; $firefox = '/Firefox/'; //Operating Systems if (stristr($info, "Windows NT 5.1")) {echo 'You are using a Windows XP Operating System ';} if (stristr($info, "Windows NT 6.0")) {echo 'You are using a Windows Vista Operating System ';} if (stristr($info, "Windows NT 6.1")) {echo 'You are using a Windows 7 Operating System ';} if (stristr($info, "Ubuntu")) {echo 'You are using an Ubuntu Operating System ';} if (stristr($info, "Mac OS")) {echo 'You are using a Macintosh Operating System ';} //Web Browsers if (stristr($info, "Chrome") !== FALSE) {stristr($info,"Safari"); $chrome = 'Chrome'; echo 'with a Chrome Web Browser ';} elseif (stristr($info, "Safari")) {echo 'with a Safari Web Browser ';} if (stristr($info, "Firefox")) {echo 'with a Firefox Web Browser ';} //If OS or Browser not found in list. if ($ubuntu || $xp || $vista || $win7) $os = true; if($firefox || $chrome || $safari || $ie9 || $ie8) $browser = true; if(!$browser || !$os){ echo'<strong>'; echo '<br />' . $_SERVER['HTTP_USER_AGENT'] . '<br /><br />Administrator someone in your work force is using an unsupported browser or OS, please email this information to the developer of the NCMR software you are using. It will allow your browser/OS combination to be used correctly. Sorry for the inconvenience.</strong> <br /><br />Please copy and paste the text above and send it to your web administrator. It will explain everything he/she needs to do.<br />';} ?> Code (markup):
if (stristr($info, "Chrome") !== FALSE) { //I'm curious as to what the next line is supposed to accomplish stristr($info,"Safari"); $chrome = 'Chrome'; echo 'with a Chrome Web Browser '; } PHP: