Matt Ridge Posted November 29, 2011 Share Posted November 29, 2011 ok, I am hoping the code is self explanatory... but if not, I'm creating a script which I will be using for something else. Basically it says if OS and browser show code under... I am looking for two things. 1. Is there a way to make it so that it can pull from a list and show that if HTTP_USER_AGENT comes back with a specific output, to say you are using X OS with Y browser? 2. The last bit, it is meant to say, if not any of the options show the info below. For some reason it's not doing that... can someone please tell me why? Thanks. <?php //Operating Systems function xp(){return(eregi("Windows NT 5.1", $_SERVER['HTTP_USER_AGENT']));} function vista(){return(eregi("Windows NT 6.0", $_SERVER['HTTP_USER_AGENT']));} function win7(){return(eregi("Windows NT 6.1", $_SERVER['HTTP_USER_AGENT']));} function ubuntu(){return(eregi("Ubuntu/", $_SERVER['HTTP_USER_AGENT']));} //Web Browsers function chrome(){ return(eregi("Chrome/", $_SERVER['HTTP_USER_AGENT']));} function safari(){ return(eregi("Safari/", $_SERVER['HTTP_USER_AGENT']));} function firefox(){ return(eregi("Firefox/", $_SERVER['HTTP_USER_AGENT']));} function ie9(){ return(eregi("MSIE 9.0", $_SERVER['HTTP_USER_AGENT']));} function ie8(){ return(eregi("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/OS combination, please email the information above 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.';} ?> Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/ Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2011 Share Posted November 29, 2011 ereg functions are deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292200 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 http://us.php.net/manual/en/function.eregi.php Use http://php.net/manual/en/function.preg-match.php Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292202 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 ereg functions are deprecated. Will that solve my issue? Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292205 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 Ok, switched it out: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 4 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 4 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 6 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 5 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 5 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 7 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292206 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 Add slashes. "/Windows NT 5.1/" Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292208 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 Add slashes. "/Windows NT 5.1/" but it says it must not be backslash, isn't that a backslash? Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292209 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 Ok, changed it up, and it still shows: You are using Windows XP with a Internet Explorer 8 web browser Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Administrator someone in your work force is using an unsupported browser/OS combination, 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. Please copy and paste the text above and send it to your web administrator. It will explain everything he/she needs to do. It is showing both variables... when it should only be showing the first line, not the rest. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292212 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 Why are you using OR? and not and? if(!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ } Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292213 Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2011 Share Posted November 29, 2011 You're using logical OR operators || where you should be using logical AND && operators. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292214 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 You're using logical OR operators || where you should be using logical AND && operators. Wouldn't the && allow all to be required? I thought the or was if one was valid, stop, otherwise continue through? I want it to show if output is not listed as one of the variables output the statement, otherwise ignore it. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292215 Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2011 Share Posted November 29, 2011 The conditional currently reads, "If ubuntu() returns false OR xp() returns false OR vista() returns false OR win7() returns false OR firefox() returns false OR chrome() returns false OR safari() returns false OR ie9() returns false OR ie8() returns false, execute the code that follows." Therefore: if( $a != 1 || $a != 2 || $a != 3 ) { // Returns TRUE if ANY conditions is true, and will always return TRUE because $a cannot equal 1, 2 and 3 simultaneously. if( $a != 1 && $a != 2 && $a != 3 ) { // Returns TRUE only if all conditions return TRUE So in your case, you need to either use logical AND operators, or change the comparison operator to == instead of != Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292223 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 The conditional currently reads, "If ubuntu() returns false OR xp() returns false OR vista() returns false OR win7() returns false OR firefox() returns false OR chrome() returns false OR safari() returns false OR ie9() returns false OR ie8() returns false, execute the code that follows." Therefore: if( $a != 1 || $a != 2 || $a != 3 ) { // Returns TRUE if ANY conditions is true, and will always return TRUE because $a cannot equal 1, 2 and 3 simultaneously. if( $a != 1 && $a != 2 && $a != 3 ) { // Returns TRUE only if all conditions return TRUE So in your case, you need to either use logical AND operators, or change the comparison operator to == instead of != Ok, I did the == I get this: Parse error: syntax error, unexpected T_IS_EQUAL in /home/pawz/public_html/kaboomlabs.com/PDI/browser.php on line 39 <?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/OS combination, 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.';} ?> What would be better to use, logicals or variables in this case? Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292229 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 Read the logic you just wrote and ask yourself if that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292231 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 I originally wanted to create this as a variable, but I wasn't too sure how to do that in this instance, because HTTP_USER_AGENT is already outputting data. Would the output be a variable? Also, there still has to be a way of showing a double negative as far as I can tell because at a time the browser and OS will not be used, and a new one will be developed. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292233 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 Read the logic you just wrote and ask yourself if that makes sense. No it doesn't, hence why I am asking for help. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292234 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 I originally wanted to create this as a variable, but I wasn't too sure how to do that in this instance, because HTTP_USER_AGENT is already outputting data. Would the output be a variable? Also, there still has to be a way of showing a double negative as far as I can tell because at a time the browser and OS will not be used, and a new one will be developed. If you want to make this easy on yourself, just use the logical AND. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292235 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 To put it in easier terms This checks to see if either one of these are not true. So if the person doesn't have Vista AND windows7 they're screwed. if(!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ } This will check that at least one is true. If one of those functions are true then continue. So if the person has at least VISTA they're okay. if(!ubuntu() && !xp() && !vista() && !win7() && !firefox() && !chrome() && !safari() && !ie9() && !ie8()){ } Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292242 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 accidentally post Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292243 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 To put it in easier terms This checks to see if either one of this are not true, continue. So if the person doesn't have Vista AND windows7 they're screwed. if(!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ } This will check that at least one is true. If one of those functions are true then continue. So if the person has at least VISTA they're okay. if(!ubuntu() && !xp() && !vista() && !win7() && !firefox() && !chrome() && !safari() && !ie9() && !ie8()){ } I had in my original 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/OS combination, please email the information above 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.';} So tell me even if have one of the variables above it shows? Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292245 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 To put it in easier terms This checks to see if either one of this are not true, continue. So if the person doesn't have Vista AND windows7 they're screwed. if(!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ } This will check that at least one is true. If one of those functions are true then continue. So if the person has at least VISTA they're okay. if(!ubuntu() && !xp() && !vista() && !win7() && !firefox() && !chrome() && !safari() && !ie9() && !ie8()){ } I had in my original 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/OS combination, please email the information above 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.';} So tell me even if have one of the variables above it shows? Yes, which why you need to use && instead of || And those are functions, not vars. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292246 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 To put it in easier terms This checks to see if either one of this are not true, continue. So if the person doesn't have Vista AND windows7 they're screwed. if(!ubuntu() || !xp() || !vista() || !win7() || !firefox() || !chrome() || !safari() || !ie9() || !ie8()){ } This will check that at least one is true. If one of those functions are true then continue. So if the person has at least VISTA they're okay. if(!ubuntu() && !xp() && !vista() && !win7() && !firefox() && !chrome() && !safari() && !ie9() && !ie8()){ } I had in my original 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/OS combination, please email the information above 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.';} So tell me even if have one of the variables above it shows? Yes, which why you need to use && instead of || And those are functions, not vars. but if I use && won't it demand that all those variables to be true so it would show up as a false positive anyway? Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292250 Share on other sites More sharing options...
Spring Posted November 29, 2011 Share Posted November 29, 2011 Well, I'm officially confused. Going to hand this over to someone else. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292252 Share on other sites More sharing options...
KevinM1 Posted November 29, 2011 Share Posted November 29, 2011 Matt, you're over thinking it. You want to check that if the user is not using Ubuntu AND is not using XP AND is not using Vista AND.... Why? Because if the user is using one of the legit options, the result of the conditional will be false, thereby making the script execute the else-clause. See: http://en.wikipedia.org/wiki/Truth_table#Logical_conjunction, specifically the second row of the first table. Conversely, the test will always return true if you use OR. Despite using some combination of legit OS and browser, there will always be options that the user is not using. See: http://en.wikipedia.org/wiki/Truth_table#Logical_disjunction, again, the second row of the first table. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292254 Share on other sites More sharing options...
Matt Ridge Posted November 29, 2011 Author Share Posted November 29, 2011 Well, I'm officially confused. Going to hand this over to someone else. What I mean is that when you type it as thus: if (!ubuntu() && !xp() && !vista() && !win7() && !firefox() && !chrome() && !safari() && !ie9() && !ie8()) IT tells me, if that all must be negative, what I want is if one of them is negative... so if someone has a good browser, but bad OS, show, not if all are negative. Quote Link to comment https://forums.phpfreaks.com/topic/252043-if-none-above-show-text-problem-is-it-shows-text-even-so/#findComment-1292255 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.