How to block images in PHP

Discussion in 'PHP' started by v123shine, Sep 13, 2010.

  1. #1
    anyone know how to block/hide images in PHP page ??

    I have site with 5000+ image from example.com, that make mysite load very slow, i want to block/hide that images from example.com.

    how can i do?

    Please help me...

    Thanks
     
    v123shine, Sep 13, 2010 IP
  2. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    you mean ,you want to hide the image path or hide what exactly?
     
    mirosoft1, Sep 14, 2010 IP
  3. VarriaStudios

    VarriaStudios Member

    Messages:
    246
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    typically i store my images inside the "assets" folder under the "img" folder and place an index.html page inside the img folder so that no one can see the images but myself

    hope this helps
    regards
     
    VarriaStudios, Sep 14, 2010 IP
  4. v123shine

    v123shine Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    thanks mirosoft1

    i meam, i want to hide image from tinypic.com in my site, because tinypic.com make my site load very slow.

    anyone know how to hide images in PHP page ??
     
    Last edited: Sep 14, 2010
    v123shine, Sep 14, 2010 IP
  5. Unlimited Media

    Unlimited Media Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Depending on how the list is being generated, you could add an if statement and check whether the URL contains the given domain name or not.
     
    Unlimited Media, Sep 14, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    If your displaying the images using a remote source (theirfore don't physically have access to modify the HTML) - you can modify the remote source...to replace all tinypic urls which can be done by using a regex with a preg_* function; another method would be calling a function (replace_tinypic) with ob_start('replace_tinypic') at the top of your script/file...and within that function place the code to replace tinypic urls, in which case we'd need the source to help you.
     
    danx10, Sep 14, 2010 IP
  7. v123shine

    v123shine Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    Thanks Unlimited media,
    can you give the example code, please!!
     
    v123shine, Sep 14, 2010 IP
  8. v123shine

    v123shine Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    Thanks danx10
    i display image using direct link from tinypic.com
    can you give the example php code, please!!
     
    v123shine, Sep 14, 2010 IP
  9. Wolf Security

    Wolf Security Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    $image = "http://www.domain.com/uploads/image.png";
    
    if (strstr($image, "domain.com") == false) {
    
        // Not hosted by domain.com - proceed ( default route )
    
    } else {
    
        // Hosted by domain.com - skip ( do nothing )
    
    }
    PHP:
     
    Wolf Security, Sep 14, 2010 IP
  10. v123shine

    v123shine Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #10
    thanks Wolf Security for the example, can you give to me the direct example, please!

    i want to hide this image from my site:
    - tinypic.com
    - s256.photobucket.com
    - s268.photobucket.com

    i try to add this in my site:

    <?php
    $image = "http://www.domain.com/uploads/image.png";
    if (strstr($image, "tinypic.com") == false) {
    // Not hosted by domain.com - proceed ( default route )
    } else {
    // Hosted by domain.com - skip ( do nothing )
    }
    ?>
    PHP:
    but still cant :'(

    Please help me!!
     
    Last edited: Sep 14, 2010
    v123shine, Sep 14, 2010 IP
  11. mazako

    mazako Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    maybe try this,

    <?php
    $image = "http://www.domain.com/uploads/image.png";
    $url = parse_url($url, PHP_URL_HOST);
    if (stristr($url, "tinypic.com") == false) {
    // Not hosted by domain.com - proceed ( default route )
    } else {
    // Hosted by domain.com - skip ( do nothing )
    }
    ?>

    regards.
     
    mazako, Sep 14, 2010 IP
  12. v123shine

    v123shine Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #12
    thanks mazako,
    I already try, but still cant :'(
     
    v123shine, Sep 15, 2010 IP