-2

Suppose the image's access is hotlinking-protected (for example by htaccess or by some other way because I have no clue) and hence, I can not access it directly in my browsers address bar via the URL verbatim (e.g. http://example.com/images/test.jpg).

But if loaded through img tag in my browser-window and with relative path (<img src="/images/test.jpg" /> inside the HTML) the image is visible on the page.

So, I wanted to ask if it is possible to make a request though CURL to get that image? I use PHP.

This question does not solve the problem php curl: how can i emulate a get request exactly like a web browser?

Community
  • 1
  • 1
dav
  • 8,931
  • 15
  • 76
  • 140
  • 2
    Loading using `img` tag **is** a direct access. If it's possible to retrieve it with browser - it's possible to retrieve it with CURL – zerkms May 05 '13 at 10:14
  • Do not ask if something is possible. Show us what you've tried so far and tell us what your problem is with that. – hakre May 05 '13 at 10:21
  • @zerkms I updated the question I made a little mistake in it, actually the path is relative in `img` tag. In this case is it considered a direct access ? – dav May 05 '13 at 10:42

1 Answers1

3

I think you just need to define a referer. A referer is not send if you input the url directly but it will be send (on default settings) when you link it.

For php:

curl_setopt($ch, CURLOPT_REFERER, 'http://stackoverflow.com/a/16383495/995926');
rekire
  • 47,260
  • 30
  • 167
  • 264
  • 2 points: 1. It will make issues for valid users 2. Bad guys with CURL will still be able to send a referrer and download an image – zerkms May 05 '13 at 10:16
  • @zerkms IMHO is is not possible to secure content in the www. It is always public... Except with some kind of auth systems. – rekire May 05 '13 at 10:17
  • yep, that's right ;-) That's why your answer at the moment isn't helpful for the OP ;-) – zerkms May 05 '13 at 10:18
  • 2
    I understood the question in this way: *How can I download that image? It works for me in a html page, but not directly.* I think my answer sloves that problem... – rekire May 05 '13 at 10:19
  • hm...... that's another point, I see now. My original though was - that OP is the service owner, who wants to protect his images. Hmmmmm – zerkms May 05 '13 at 10:21
  • @zerkms: maybe the OP is a bad guy with cURL? `;-)` – halfer May 05 '13 at 11:02
  • 1
    @halfer: yea, I am the bad guy :D – dav May 05 '13 at 17:55
  • @Davo: do something good today, to balance out your karma! – halfer May 05 '13 at 18:07
  • @halfer I do not believe in karma ;) IMHO our life is just the result of our thoughts, nothing more – dav May 05 '13 at 18:56
  • 1
    @halfer: answerer's karma got worse as well actually – zerkms May 07 '13 at 01:07