<?php //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']));} // do something if XP and Chrome if(xp() && chrome()){echo 'You are using Windows XP with a Chrome web browser';} // do something if XP and IE8 if(xp() && ie8()){echo 'You are using Windows XP with a Internet Explorer 8 web browser';} // do something if Windows 7 and IE9 if(win7() && ie9()){echo 'You are using Windows 7 with a Internet Explorer 9 web browser';} // do something if Windows Vista and IE9 if(vista() && ie9()){echo 'You are using Windows Vista with a Internet Explorer 9 web browser';} // do something if Windows Vista and IE8 if(vista() && ie8()){echo 'You are using Windows Vista with a Internet Explorer 8 web browser';} // do something if Ubuntu and Firefox if(ubuntu() && firefox()){echo 'You are using Ubuntu with a Firefox web browser';} if (!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ 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 last bit of the code, if (!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ 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): I am trying to make it so that if none of the variables are shown post the message below, but at the same time if one of them is there like the OS, but not the browser the error will post, otherwise ignore. Is this possible?
What about: $os_rec = false; if (ubuntu() || xp() || vista() || win7()) $os_rec = true; $browser_rec = false; if(firefox() || chrome() || safari() || ie9() || ie8()) $browser_rec = true if(!$browser_req || !$os_rec){ //do error stuff } PHP:
That looks like it would work, how does it work exactly? I understand what I am looking at, but $os_rec is a variable correct that was self created?
$os_rec and $browser_req are just booleans that are originally set to false, but are then set to true if your system recognises them as an OS/browser that you are looking for. If either of them are false you know something didn't match up and then you can go on to handle it how you want.