+ Reply to Thread
Results 1 to 9 of 9

Thread: Code help

  1. #1
    ZeptOr's Avatar
    ZeptOr is offline x10 Sophmore ZeptOr is an unknown quantity at this point
    Join Date
    Sep 2005
    Posts
    221

    Code help

    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?

  2. #2
    Chris Z's Avatar
    Chris Z is offline x10 Spammer Chris Z is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Alabama, USA
    Posts
    2,802

    Re: Code help

    do a little something like this
    PHP Code:
    <?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 by Chris Z; 11-22-2006 at 12:27 AM.
    -Chris Z
    Retired Account Manager


  3. #3
    ZeptOr's Avatar
    ZeptOr is offline x10 Sophmore ZeptOr is an unknown quantity at this point
    Join Date
    Sep 2005
    Posts
    221

    Re: Code help

    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?

  4. #4
    Micro is offline Retired staff (11-12-2008) Micro is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    West Midlands
    Posts
    1,301

    Re: Code help

    Except dont put the echo in there, its not needed and wont be seen if its just a img src="phpscript"
    Micro

  5. #5
    ZeptOr's Avatar
    ZeptOr is offline x10 Sophmore ZeptOr is an unknown quantity at this point
    Join Date
    Sep 2005
    Posts
    221

    Re: Code help

    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

  6. #6
    aking47 is offline x10Hosting Member aking47 is an unknown quantity at this point
    Join Date
    Oct 2006
    Posts
    13

    Re: Code help

    PHP Code:
     <?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);
      }

  7. #7
    ZeptOr's Avatar
    ZeptOr is offline x10 Sophmore ZeptOr is an unknown quantity at this point
    Join Date
    Sep 2005
    Posts
    221

    Re: Code help

    what if the images are png, does that matter?

  8. #8
    aking47 is offline x10Hosting Member aking47 is an unknown quantity at this point
    Join Date
    Oct 2006
    Posts
    13

    Re: Code help

    change the @imagecreatefromjpeg to @imagecreatefrompng

  9. #9
    Torch's Avatar
    Torch is offline x10 Lieutenant Torch is an unknown quantity at this point
    Join Date
    Apr 2006
    Location
    Belgrade, Serbia
    Posts
    317

    Re: Code help

    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 Code:
    <?
    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.

+ Reply to Thread

Similar Threads

  1. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  2. how can i convert Php pages and code into asp pages and code
    By n4tec in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 01-10-2009, 09:40 PM
  3. Ad Code Question
    By reiterb in forum Free Hosting
    Replies: 1
    Last Post: 08-18-2005, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers