最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - All possible ways to read a file from a remote server - Stack Overflow

programmeradmin0浏览0评论

i want to provide most possible flexibility for my script and so i need all possible ways in php and javascript to read the content(not sourcecode) of a php file from a remote server. so far i found curl, fopen and include for php and none for javascript, but i dont even know if this is possible with javascript. Thanks for any hint.

i want to provide most possible flexibility for my script and so i need all possible ways in php and javascript to read the content(not sourcecode) of a php file from a remote server. so far i found curl, fopen and include for php and none for javascript, but i dont even know if this is possible with javascript. Thanks for any hint.

Share Improve this question asked Sep 21, 2009 at 2:30 GiovanniGiovanni
Add a ment  | 

3 Answers 3

Reset to default 3

PHP:

  - fopen() + fread()
  - file_get_contents()
  - curl
  - executing shell mands
        `wget 'www.google.' -O saved.htm`;
        $result = `cat saved.htm`;

JavaScript:

  // not for remote server
  var req = new XMLHttpRequest();
  req.open('GET', 'http://www.google.', false);
  req.send(null);
  if (req.readyState==4) alert(req.responseText);

You've got the major options for PHP figured out.

As for javascript (assuming it's running in a web browser), the same-origin policy will plicate things.

Possible workaround for Javascript include:

  • Using a script-tag proxy

  • Using a PHP proxy script on the domain that your page is loaded from. Your javascript asks the PHP script to grab the remote content. PHP script does that, and outputs the contents back to you javascript.

Javascript is a client side scripting language primarily, you can't just simply get an external resource with it without either

  • server-side help ( xhr to server-side page to do curl/wget )
  • the resource has to be on your domain and you can XMLHttpRequest it without server-side help.
发布评论

评论列表(0)

  1. 暂无评论