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

i want to provide most possible flexibility for my script and so i need all possible ways in php and ja

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745153034a4613950.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信