admin管理员组文章数量:1414621
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 GiovanniGiovanni3 Answers
Reset to default 3PHP:
- 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.
本文标签: phpAll possible ways to read a file from a remote serverStack Overflow
版权声明:本文标题:php - All possible ways to read a file from a remote server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745153033a2645002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论