Jump to content

If none above show text... problem is it shows text even so.


Matt Ridge

Recommended Posts

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.';}


?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 !=

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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()){

}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Well, I'm officially confused.

:shrug:

 

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.

 

 

 

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.