Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 PHP 中实现一个代理来加载图像文件,我发现了这样的东西
<?php header('Content-Type: image/png'); if (isset($_POST['remote_url'])) { echo file_get_contents($_POST['remote_url']); } ?>
(1)有没有更好的方法来做到这一点?或增强这个?(在速度和服务器加载方面)
(2) 如何避免未经授权使用此 PHP 脚本?
(1) 至少我会添加一些错误处理。获取远程资源可能会以超时、404 或任何其他 HTTP 错误结束。反过来,这可能会让您切换file_get_contents到具有更多配置选项的 CURL。顺便说一下,一些测试表明它比 运行得更快file_get_contents。
file_get_contents
(2) 如果你使用会话,这里可能适合授权。另一个(但不太可靠)选项是检查HTTP_REFERER标题内容。
HTTP_REFERER