file-get-contents

file_get_contents and error codes

做~自己de王妃 提交于 2019-12-05 09:02:48
I'm downloading a file from the web with file_get_contents . Sometimes I get 503 Service Unavailable or 404 Not Found . Warning: file_get_contents(http://somewhereoverinternets.com) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in somesourcefile.php on line 20 How can I get this error code - 503 ? 404, 200? To make the process for these cases. Try curl instead: function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT

php file_get_contents($url) & turns into &

梦想的初衷 提交于 2019-12-05 03:09:55
I am trying to make a request to the coinbase api like this $url = "https://api.gdax.com/products/BTC-USD/candles?start=".date($format,$starting_date)."&end=".date($format,$ending_date)."&granularity=".$granularity; and then I pass that in file_get_contents($url) but it gives me an error file_get_contents( https://api.gdax.com/products/BTC-USD/candles?start=2015-05-07&end=2015-05-08&granularity=900 ): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request. The problem of course is when the '&' gets changed into '&'. Ilgıt Yıldırım It seems you need define an user agent. Try this;

Posting a file to a web service with Guzzle

荒凉一梦 提交于 2019-12-05 01:39:17
问题 I've been trying for several hours to make a POST request that sends a file. First tried a simple file_get_contents() with stream context, doesn't seem to work. I never get a response back while the GET on a different URL works. I searched on the web for an HTTP client and found Guzzle which was downloaded 400k times on Packagist; I decided to try out this technology. Well documented but, alas, getting an error also when posting that damn file. $request = $client ->post('/files/') -

Using proxy with file_get_contents

蹲街弑〆低调 提交于 2019-12-05 01:36:57
问题 I am getting data for my application from a website, say x.com. I use the php function file_get_contents() to fetch the data. It is sure that , my server's ip address will be shown in x.com 's logs. Is there any way to hide my server's ip without using proxy? If I have a proxy ,how to use it with file_get_contents() ? I need to send the request in both HTTP POST and HTTP GET methods 回答1: test.php using http://ifconfig.me/ip code modified from http://www.php.net/manual/en/function.file-get

How can one detect if a server/script is accessing their site through cURL/file_get_contents()? (excluding user-agents and IP addresses)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 22:02:58
I've come across a question where a user is having difficulties accessing an image through a script (using cURL / file_get_contents() ): How to save an image from url using PHP? The image link seems to return a 403 error when using file_get_contents() to request it. But in cURL, a more detailed error is returned: You were denied access to the system. Turn off the engine or Surf Proxy, Fake IP if you really want to access. Proxy or not accepted from any Web tools Intrusion Prevention System. Binh Minh Online Data Services @ 2008 - 2012 I also failed to access the same image after fiddling

Elastic search and Codeigniter (PHP)

纵然是瞬间 提交于 2019-12-04 21:07:40
问题 I'm trying using ElasticSearch with Codeigniter framework. What i did is just install ElasticSearch and copyed ( :P ) a good PHP library found on the web to CI libraries: class Elasticsearch { public $config_file = 'elasticsearch'; public $index; function __construct($index = false){ $CI =& get_instance(); $CI->config->load($this->config_file); $this->server = $CI->config->item('es_server'); } function call($path, $http = array()){ if (!$this->index) throw new Exception('$this->index needs a

file_get_contents from multiple url

我的未来我决定 提交于 2019-12-04 17:40:13
i want to save page content to files from multiple url. For start i have sites url from array $site = array( 'url' => 'http://onesite.com/index.php?c='.$row['code0'].'&o='.$row['code1'].'&y='.$row['code2'].'&a='.$row['cod3'].'&sid=', 'selector' => 'table.tabel tr' ); For saveving files I have try: foreach($site as $n) { $referer = 'reffername'; $header[] = "Accept: text/xml,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300";

PHP - how to get main HTML content like Reader Mode in Firefox

给你一囗甜甜゛ 提交于 2019-12-04 14:40:55
问题 in android Firefox app and safari iPad we can read only main content by "Reader Mode". read more... How to recognize only main content in HTML with PHP? I need to detect main news like Firefox or safari by php for example I get news from bbcsite.com/news/123 by this code: <?php $html = file_get_contents('http://bbcsite.com/news/123'); ?> then show only main news without ads and ... like Firefox and safari. I find fivefilters.org . this site can get content!!! thank you 回答1: A new PHP library

file_get_contents displaying image incorrectly

…衆ロ難τιáo~ 提交于 2019-12-04 14:38:34
I'm trying to display generic websites and URLs as part of my own site. Here's part of the relatively simple code I'm using: browse.php <? $enteredurl = $_GET["url"]; $page = file_get_contents($enteredurl); echo $page; ?> Ignoring the fact that some links/images will not work if the URls are relative rather than absolute, this works just fine. Pages are accessed using $_GET, something like browse.php?url= http://itracki.com The webpage will display as expected. However, when I'm trying to get something else, like an image, I get something like this, which I'm thinking is binary or something?

Accept cookies using cURL?

我的未来我决定 提交于 2019-12-04 12:41:59
I've been trying to get the contents of a webpage using cURL, but have trouble getting cURL to accept cookies. For example, on Target.com, when I cURL it, it still says that I have to enable cookies. Here is my code: $url = "http://www.target.com/p/Acer-Gateway-15-6-Laptop-PC-NV57H77u-with-320GB-Hard-Drive-4GB-Memory-Black/-/A-13996190#?lnk=sc_qi_detailbutton"; $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL,$url); // set url to post to curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT