[英]how to print the contents of a remote .php file
my code: 我的代码:
$fp = fopen('http://192.168.127.128/test.php', 'rb');
while(!feof($fp)){
echo fgets($fp);
}
fclose($fp);
and the test.php is: 而test.php是:
<?php
phpinfo();
I just want to print the contents of test.php, but it prints the result of test.php actually. 我只想打印test.php的内容,但实际上打印了test.php的结果。 What should I do to print the contents of test.php?
我应该怎么做才能打印test.php的内容?
If you want to get the contents / code of a remote PHP file, you will typically need to SFTP it off the server or retrieve it in another way where it isn't executed. 如果要获取远程PHP文件的内容/代码,通常需要从服务器上SFTP对其进行FTP传输,或者以不执行该文件的另一种方式对其进行检索。 If you run the web server and don't want to execute PHP files at all, you can configure the web server to render the PHP code as a text file.
如果您运行Web服务器并且根本不想执行PHP文件,则可以配置Web服务器以将PHP代码呈现为文本文件。
When you access a PHP file over a URL like http://192.168.127.128/test.php
, the PHP file will typically be interpreted by the web server and you will only receive the output result. 当您通过诸如
http://192.168.127.128/test.php
之类的URL访问PHP文件时,Web服务器通常会解释该PHP文件,并且您只会收到输出结果。
The best way is using cURL. 最好的方法是使用cURL。
$url = 'http://192.168.127.128/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
echo $return;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.