Can't include file on remote server

倖福魔咒の 提交于 2019-12-18 06:58:03

问题


My problem is that I can't include a file on a remote server.

<?php
  echo "Including\n";
  require_once("http://xx.xxx.xxx.xx:8080/path/to/myfile.inc");
  echo "Done..\n";
?>

The script fails at the require_once function. I'm running the script with: php -d allow_url_include=On script.php but to make sure I have set allow_url_include and allow_url_fopen to On in php.ini

If I copy http://xx.xxx.xxx.xx:8080/path/to/myfile.inc to the browser I'm served the file. I have also tried to include other remote files (on standard port 80), but still no luck

Where I get really confused is that everything works from my local computers at my office (mac, ubuntu), but not from our servers. I have tested it on 2 different servers, a virtual and a dedicated. I can get the file with fopen().


回答1:


This can be done by setting allow_url_include to on on php.ini.

But, as mentioned in comments, this opens a

huge

security hole on your application.




回答2:


Require_Once should be used for local files only. If you want to get a remote file use file_get_contents. Remember if you are trying to include php from a remote server like that, it will be really insecure or the php will be executed on the remote server.



来源:https://stackoverflow.com/questions/9498885/cant-include-file-on-remote-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!