supanova Posted February 1, 2011 Share Posted February 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/ Share on other sites More sharing options...
requinix Posted February 1, 2011 Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168148 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168156 Share on other sites More sharing options...
jcbones Posted February 1, 2011 Share Posted February 1, 2011 1. If it IS your webspace, change the .htaccess to allow calls from your other space. 2. If it IS NOT your space, leave it alone, the owner doesn't want you eating his bandwidth. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168159 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168173 Share on other sites More sharing options...
BlueSkyIS Posted February 1, 2011 Share Posted February 1, 2011 1. If it IS your webspace, change the .htaccess to allow calls from your other space. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168181 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168184 Share on other sites More sharing options...
BlueSkyIS Posted February 1, 2011 Share Posted February 1, 2011 you can't get around the htaccess restriction unless htaccess is edited. period. maybe see if they will give you ftp access instead. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168186 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 Well, I know it can be done, because I use something that does it every day. It doesn't open the page directly, but it gets the pictures using some other method. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168191 Share on other sites More sharing options...
requinix Posted February 1, 2011 Share Posted February 1, 2011 Are you talking about the area requiring a username and password, or what? If so then what I said before still stands. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168199 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 No. This is pages that use htaccess to prevent hotlinking. I need to find the method to pull the picture from the page without htaccess trying to redirect. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168208 Share on other sites More sharing options...
BlueSkyIS Posted February 1, 2011 Share Posted February 1, 2011 there are several ways to use .htaccess to prevent retrieval of a file from a remote host. if done in the strictest way, no, neither your nor your 'something' can retrieve a file from an external server. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168311 Share on other sites More sharing options...
Pikachu2000 Posted February 1, 2011 Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168336 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168475 Share on other sites More sharing options...
litebearer Posted February 1, 2011 Share Posted February 1, 2011 <-- checking to see if the sound system is working Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168479 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 *sigh* Please read the code and understand it's not getting around the safeguard, because the protection is there to defeat hotlinking, and as you can see from the above code, there is not hotlinking taking place. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168485 Share on other sites More sharing options...
jcbones Posted February 1, 2011 Share Posted February 1, 2011 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'] Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168558 Share on other sites More sharing options...
supanova Posted February 1, 2011 Author Share Posted February 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168560 Share on other sites More sharing options...
jcbones Posted February 1, 2011 Share Posted February 1, 2011 Inline linking (also known as hotlinking, leeching, piggy-backing, direct linking, offsite image grabs) Maybe, you don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/226301-how-to-load-files-from-webpage-protected-by-htaccess/#findComment-1168582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.