PHP获取远程文件
if(!($contents=file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=AMZN&e=.csv&f=slldltlclohgv'))){
die('fail to open yahoo');
};
echo $contents;
为什么平均要刷新3-4下才有一次成功,其他都会出现一个警告,提示 HTTP request failed!
------解决方案--------------------
- C/C++ code
Bart Friederichs 16-Apr-2012 12:17 file_get_contents can do a POST, create a context for that first: $opts = array('http' => array( 'method' => 'POST', 'header' => "Content-Type: text/xml\r\n". "Authorization: Basic ".base64_encode("$https_user:$https_password")."\r\n", 'content' => $body, 'timeout' => 60 ) ); $context = stream_context_create($opts); $url = 'https://'.$https_server; $result = file_get_contents($url, false, $context, -1, 40000); pperegrina 21-Dec-2011 11:30 For those having this problem when trying to get_file_contents(url): Warning: file_get_contents(url): failed to open stream: HTTP request failed! in xx on line yy If you are behind a SonicWall firewall, read this: https://bugs.php.net/bug.php?id=40197 (this little line: uncheck a box in the internal settings of the firewall labled "Enforce Host Tag Search with for CFS") Apparently by default SonicWall blocks any HTTP request without a "Host:" header, which is the case in the PHP get_file_contents(url) implementation. This is why, if you try to get the same URL from the same machine with cURL our wget, it works. I hope this will be useful to someone, it took me hours to find out :) godwraith01 at yahoo dot com 11-Oct-2011 04:16 I experienced a problem in using hostnames instead straight IP with some server destinations. If i use file_get_contents("www.jbossServer.example/app1",...) i will get an 'Invalid hostname' from the server i'm calling. This is because file_get_contents probably will rewrite your request after getting the IP, obtaining the same thing as : file_get_contents("xxx.yyy.www.zzz/app1",...) And you know that many servers will deny you access if you go through IP addressing in the request. With cURL this problem doesn't exists. It resolves the hostname leaving the request as you set it, so the server is not rude in response. <div class="clear"> </div>

本文討論了PHP中的crypt()和password_hash()的差異,以進行密碼哈希,重點介紹其實施,安全性和對現代Web應用程序的適用性。

文章討論了通過輸入驗證,輸出編碼以及使用OWASP ESAPI和HTML淨化器之類的工具來防止PHP中的跨站點腳本(XSS)。

自動加載PHP會在需要時自動加載類文件,從而通過減少內存使用和增強代碼組織來提高性能。最佳實踐包括使用PSR-4和有效組織代碼。

本文討論了在PHP中管理文件上傳大小的管理,重點是2MB的默認限制以及如何通過修改PHP.INI設置來增加它。

本文討論了PHP 7.1中引入的PHP中的無效類型,允許變量或參數為指定類型或NULL。它突出顯示了諸如提高可讀性,類型安全性和明確意圖的好處,並解釋瞭如何聲明

本文討論了unset()和unlink()功能在編程中的差異,重點關注其目的和用例。 unset()從內存中刪除變量,而unlink()從文件系統中刪除文件。兩者都對效率至關重要


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器