Code help

ZeptOr

New Member
Messages
442
Reaction score
0
Points
0
Well, because I was not able to solve my problem on how to get a gradient transparent background working in IE, I decided to do something different. I want to have the background image show for Firefox users, but for IE users I want it to show nothing. How do I got about doing this?
 

Chris Z

Active Member
Messages
5,603
Reaction score
0
Points
36
do a little something like this
PHP:
<?php
function agent($browser) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
return strstr($useragent, $browser);
}
if(agent('Firefox') != FALSE) 
  {
    $img = @imagecreatefromjpeg("http://www.mysite.com/my_image.jpg");
    ImageDestroy($img);
   }

else 
  {
    echo "Sorry, it appears you do not have Firefox, which means you cannot see the image.";  
  }
 
Last edited:

ZeptOr

New Member
Messages
442
Reaction score
0
Points
0
This is interesting. I am not much of a coder, I know HTML but thats it.

Does this basically say if the viewer isn't using Firefox, then destroy the image that I only want displayed in Firefox?
 

Micro

Retired staff <i> (11-12-2008)</I>
Messages
1,301
Reaction score
0
Points
36
Except dont put the echo in there, its not needed and wont be seen if its just a img src="phpscript"
 

ZeptOr

New Member
Messages
442
Reaction score
0
Points
0
okay what about this

instead of getting rid of the image if the user is using IE, how would you code something so that it replaces a background image with another one if the user is using IE
 

aking47

New Member
Messages
13
Reaction score
0
Points
0
PHP:
 <?php
function agent($browser) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
return strstr($useragent, $browser);
}
if(agent('Firefox') != FALSE) 
  {
    $img = @imagecreatefromjpeg("http://www.mysite.com/my_image.jpg");
    ImageDestroy($img);
   }

else 
  {
    // This bit here:
    $img = @imagecreatefromjpeg("http://www.mysite.com/internetexplorer_image.jpg");
    ImageDestroy($img);
  }
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
Actually, since IE7 has full support for alpha transparency, there is no need to hide the image from it. I modified Chis' code a bit to not do so...
PHP:
<?
function agent($browser){
   $useragent = $_SERVER['HTTP_USER_AGENT'];
return stripos($useragent,$browser);
}

if(agent('Firefox') !== false or agent('MSIE 7') !== false){
   $img = @imagecreatefrompng("http://www.mysite.com/my_image.png");
   imagedestroy($img);
}
else{
   $img = @imagecreatefromjpg("http://www.mysite.com/my_image.jpg"); //Some other image without alpha
   imagedestroy($img);
}
?>

So, now the image would be shown to FF and IE7 users, but all others will see the second image.
 
Top