Jump to content

Recommended Posts

I'm writing a script that opens a webpage and pulls out the pictures for editing.

 

The problem I'm having is the pictures are protected from hotlinking with htaccess. The script is on a different domain.

 

I know it's possible to do this but after much searching and experimentation I can't work it out.

 

Any ideas?

You can do it with file_get_contents() with a bit of effort.

 

cURL has some options you can set to download whatever, including a username/password to log in with. That's probably the easiest way.

Thanks for the reply. I tried file_get_contents but that does also fail at htaccess. Using GD I can load the pictures but htaccess defeats it. What extra steps would be required to get around it?

 

I've never used curl so I'm completely unfamiliar with it.

Thanks for your reply, but you don't seem to understand. I'm not looking to hotlink the pictures. I'm loading them in order to edit them. The purpose of the script is to save time download the pictures, and editing them locally, manually making changes. The purpose of the script is to streamline and automate that process.

Just to reiterate, the script loads the pictures so I can easily make edits. But if htaccess is present it blocks the request because it's not coming from the same page. I'm not hotlinking the picture, just automating the edit rather than downloading one picture at a time.

 

What I need to know is how to get around the htaccess restriction, which is aimed at stopping something else entirely. The domain owners wouldn't have a problem with it as its for promotional purposes, but I can't expect them to edit their htaccess for me.

You aren't going to find many people here willing to help you defeat a safeguard or protection put in place by a site to protect their assets. If this would be so beneficial to the site involved, surely you can contact them and they'd be thrilled to give you whatever access you need.

As this is the internet I can understand the suspicion, and misreading what I want to do, sad though it is.

 

I believe this is the right approach, though it's not working yet:

 

$referrer = "www.domain.com";

 

$opts = array(

'http'=> array(

'method'=>"GET",

'header'=> "accept-language: en\r\n" . "Host: $referrer\r\n" . "Referer: http://$referrer\r\n" // Setting the http-referer

)

);

 

$context = stream_context_create($opts);

$pic = file_get_contents("http://www.domain.com/pic.jpg", false, $context);

 

I'm thinking either the referrer information is missing something or file_get_contents isn't the right method to get the picture.

You can call it whatever you wish, receiving an image from a remote server = hotlinking.  I don't care if you are trying to "edit" it.  Anytime you request that image from outside of it's native domain, that is hotlinking (at least as the server sees it).

 

If the administrators of that site has an .htaccess file that disables ANY call from outside of the native domain.  YOU WILL NOT GET THE IMAGE.

 

You aren't going to find many people here willing to help you defeat a safeguard or protection put in place by a site to protect their assets. If this would be so beneficial to the site involved' date=' surely you can contact them and they'd be thrilled to give you whatever access you need.[/quote']

 

 

You clearly don't understand the concept of hotlinking.

 

Thanks to all that offered help, until the above poster derailed this topic. I really appreciate your attempts to help. I'll continue looking for the solution elsewhere.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.