简体   繁体   中英

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:

<?php
phpinfo();

I just want to print the contents of test.php, but it prints the result of test.php actually. What should I do to print the contents of 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. 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.

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.

The best way is using 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM