Arman
Arman

Reputation: 113

PHP fopen not working on one particular domain

I'm trying to download file from remote url with fopen function.

Problem it's function return false from one website that i need. From other domains functions works fine.

How could it be? Maybe have some options in php? Or that website can protect file from some access(but from browser file available)?

Upvotes: 2

Views: 279

Answers (2)

arkascha
arkascha

Reputation: 42935

There are a number of checks the server side can do to prevent "miss usage" of their service. One example is a check of the "HTTP Referer Header" which indicates that your request is done by a browser navigating from a link to the object.

You can simulate all that if you want to, but for that you have to find out exactly what the difference is between your request and one the browser successfully makes. Two things to do for that:

  1. find out the exact error message you receive back. Easiest for that is to use php's cURL extension instead of file_open() for your request, it allows you to dump everything you get back. There might be valuable information like a reason in the reply.

  2. monitor both requests by means of a network sniffer, for example tcpdump or wireshark. The comparison of both requests allows to tell the exact difference. That again is the information you need to precisely rebuilt the browsers request in your script.

Upvotes: 1

Ivijan Stefan Stipić
Ivijan Stefan Stipić

Reputation: 6678

On some shared hosting or some VPS fopen not work or are disabled inside PHP. Try to use CURL to get contnt. If that not work, the last solution (only if you send some informations via GET but not to recive data) is to use <img> tag and inside "src" to send request. That work ONLY if you send informations, but if you need to recive something, you need to use or AJAX or cURL.

Upvotes: 0

Related Questions