1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Hide/cloak the location of my images?

Discussion in 'PHP' started by Kerosene, Dec 20, 2007.

  1. #1
    Can I use php to hide the real location of my images?

    I'd like my source to look something like:
    <img src="myphpscript.php?img=345" />

    And have myphpscript.php grab the image from the real location
    e.g
    /folder/pix/345.jpg
     
    Kerosene, Dec 20, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, you definitely can.
     
    hogan_h, Dec 20, 2007 IP
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    Thanks for your input :rolleyes:

    Can anyone give me some slightly more intelligent help?
     
    Kerosene, Dec 20, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dude, you asked a question and i answered it, the question was "Can I use php to hide the real location of my images?"

    Did you want something else? If you wanted the code, then you should have said so...

    You should formulate your questions better, before insulting people trying to help you and demanding "intelligent answer". Ask a dumb question and the answer will be the same.
     
    hogan_h, Dec 20, 2007 IP
  5. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #5
    I don't want to get involved in an argument. If it wasn't obvious that I'd like some help with what I'm trying to do, then I apologize.

    How's this then...

    "Any idea how to do it?"

    EDIT : Actually, forget it. I found out how to do it.
     
    Kerosene, Dec 20, 2007 IP
  6. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi Kerosene, no problem, apology accepted, sorry if i offended you. I was actually writing the code and then saw you already solved it (I saw your code too, before you edited it ;)).

    Here just few suggestions, for securing the script better:
    1) If images are only numbers, then do intval($_GET['img']).
    2) Check the passed parameter for file existance before you output it. In that case you could output an "blank.jpg", or "nohacking.jpg", etc, which is better than generating a "broken" image in browser or outputing the error which will give the path of your images folder away.

    There is more to it, but this should be enough for the moment...

    Take care
     
    hogan_h, Dec 20, 2007 IP
  7. Sohan

    Sohan Peon

    Messages:
    2,330
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    0
    #7
    just use a proxy?
     
    Sohan, Dec 20, 2007 IP
  8. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #8
    You can use mod_rewrite. PS: People can still hotlink to your images through that btw.
     
    tushardhoot1, Dec 20, 2007 IP
  9. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #9
    Can I ask he purpose of that hiding ?

    The easiest/fastest solution is with Apache "mod rewite" module as tushardhoot1 said.
    With this method you don't need a .php file, only a couple of lines on your .htaccess file:
    Example
    
    RewriteEngine on
    RewriteRule    ^inexistentPhpScript.php?img=(.*)&f=(.*)$   /folder/$2/$1.jpg   [L]
    
    Code (markup):
    But if you want to limit the amount of images served per IP, or another task .... then you'll need to code by yourself.
     
    ajsa52, Dec 21, 2007 IP
    Kerosene likes this.
  10. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #10
    I'm trying to hide ebay auction pics from Google ... 'nuff said :p

    I tried the htaccess method, and as much as I like the simplicity of it - I ran a few tests and for some reason the php method actually turned out to be faster.
     
    Kerosene, Dec 22, 2007 IP