简体   繁体   English

我如何通过调用URL打印php代码?我按文件名尝试过,但是我想通过URL打印

[英]How can i print php code by call url?I tried by file name but i want to print by url

I am trying to print php code on web page by using my URL. 我正在尝试使用我的URL在网页上打印php代码。 I know by file name i can print php code using "show_source('filename.php');" 我知道通过文件名,我可以使用“ show_source('filename.php');”打印php代码。 but i want to print code by URL, not by file. 但我想通过URL而不是文件来打印代码。

I tried:- 我试过了:-

<?php
show_source("http://URL.com/index.php");
?>

I also tried this code:- 我也尝试过这段代码:

<?php
    $c = curl_init('http://URL.com');
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt(... other options you want...)

    $html = curl_exec($c);

    if (curl_error($c))
        die(curl_error($c));

    // Get the status code
     $status = curl_getinfo($c, CURLINFO_HTTP_CODE);

    curl_close($c);

    I also tried this code:-

    $html = file_get_contents('https://www.URl.com');
    print_r ($html) ;
?>

Short answer: If the web server is configured correctly, it should be impossible to do what you are trying to do. 简短的回答:如果正确配置了Web服务器,则应该无法执行您尝试执行的操作。

A correctly configured web server will only send content after PHP has processed it. 正确配置的Web服务器仅在PHP处理完内容后才发送内容。 If the web server is sending raw PHP when a .php file is requested, it is misconfigured. 如果在请求.php文件时Web服务器正在发送原始PHP,则配置错误。 If you are trying to view your own PHP files from a server you control, you can try making a copy of the PHP files and changing the extension to .phps , which the server should send as raw PHP code. 如果尝试从您控制的服务器查看自己的PHP文件,则可以尝试制作PHP文件的副本,并将扩展名更改为.phps ,服务器应将其作为原始PHP代码发送。 Note that this will expose the PHP source to the web, which could present a security risk. 请注意,这会将PHP源暴露给Web,这可能会带来安全风险。

As Mr. Squidward already mentioned, this should not be possible. 正如Squidward先生已经提到的那样,这是不可能的。 Otherwise this would be a major security breach since you can store passwords for databases in the PHP files. 否则,这将是一个重大的安全漏洞,因为您可以将数据库的密码存储在PHP文件中。

A possible solution for your problem would be that you create a REST API on the second server and there you have a function that gets the content of a specific file and returns it in JSON. 针对您的问题的一种可能的解决方案是,您在第二台服务器上创建一个REST API,并且那里有一个函数可以获取特定文件的内容并以JSON返回。

But ensure that you don't pass any critical data as passwords or user-data in it. 但是请确保不要在其中传递任何重要数据作为密码或用户数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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