how is php, would i be able to dectect which browser a user is using so that i can change. i have a picture that i want to change depending on the browser, for example the internet explorer users will see a gif and the mozzila etc will see a png. cheers in advance. martin
PHP: if(($string = strstr($_SERVER['HTTP_USER_AGENT'], 'mozilla')) == TRUE) { $imgext = '.png'; } else { $imgext = '.gif'; } echo '<img src="image'.$imgext.'">'; You could shorten this to: PHP: $string = strstr($_SERVER['HTTP_USER_AGENT'], 'mozilla') ? $imgext = '.png' : $imgext = '.gif'; the strstr() is untested, i've not checked if it returns true but i'm sure you can work on that
No probs, i just added an improvement (the 2nd piece of code). You may want to fiddle with the terms (str needle) too as Opera can probably deal with .pngs as well as mozilla does
why assign to $string rather than: PHP: $imgext = strstr($_SERVER['HTTP_USER_AGENT'], 'mozilla') ? '.png' : '.gif'; ?
Ok, what i have done is this... PHP: if(STRPOS($_SERVER['HTTP_USER_AGENT'], 'Moz') == 0) { echo '<link rel="stylesheet" type="text/css" href="bluehaze.moz.css" title="Blue Haze stylesheet" />'; } else { echo '<link rel="stylesheet" type="text/css" href="bluehaze.ie.css" title="Blue Haze stylesheet" />'; } At http://www.ashfordtownsc.co.uk, ps don't laugh. it still doesn't seem to be working, ie comes up as mozzila?!?
It's because IE returns something like: "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)" You might try: PHP: if(STRPOS($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { echo '<link rel="stylesheet" type="text/css" href="bluehaze.ie.css" title="Blue Haze stylesheet" />'; } else { echo '<link rel="stylesheet" type="text/css" href="bluehaze.moz.css" title="Blue Haze stylesheet" />'; }
so i have changed it again, PHP: <?php if(STRPOS($_SERVER['HTTP_USER_AGENT'], 'Gecko') == 0) { echo '<link rel="stylesheet" type="text/css" href="bluehaze.moz.css" title="Blue Haze stylesheet" />'; } else { echo '<link rel="stylesheet" type="text/css" href="bluehaze.ie.css" title="Blue Haze stylesheet" />'; } ?> and now it works in reverse!? why, i can use it as it is but i want to know why it is doing this edit: am using that last posting of code that was sugested and that works cheers.
Just an off-the-topic post, but if you use strpos to search for something that isn't there, it returns a boolean false. Now if you use it to search for something that is there, and is the at the very beginning of the string, it returns a zero, or, a boolean false. Am I correct? I always have to do a <?php $foo=strpos(" " . $bar, $baz);?> to use $foo as a boolean true or false... (sorry, I figured all the strpos users here might have a better idea as to how to fix this quicker and less memory intensive)
Mozilla/Gecko based browsers can use PNG's proerly, IE cannot. and wouldent it be quicker to use get_browser(); for detecting the browser
I don't because i don't know abaout it, thats why i was posting in the first place. how would you use get_browser(); to detect which broswer is using