简体   繁体   English

php 文件可以像 html 文件一样在互联网上查看吗?

[英]Can php files be viewed across the internet like html files?

if I want to view the code of a web page written in html I just need to right click and select view source.如果我想查看用 html 编写的网页代码,我只需要右键单击并选择查看源代码。 Can the same be done with php files so I can learn how certain tasks are being accomplished?可以用 php 文件做同样的事情,这样我就可以了解某些任务是如何完成的吗? Is there a way to hide the code?有没有办法隐藏代码?

Unless the server is very improperly set up, no.除非服务器设置非常不正确,否则不会。 Very no.非常没有。

For example, at the top of my "includes/database.php" file, I have three lines that look like例如,在我的“includes/database.php”文件的顶部,我有三行看起来像

$host = "localhost";
$username = "myuser";
$password = "mypassword";

You can see why I'd not want that publicly visible...你可以明白为什么我不想让公众看到......

No, they can't.不,他们不能。 PHP is a server-side scripting language, the browser never actually sees the php code. PHP 是一种服务器端脚本语言,浏览器永远不会真正看到 php 代码。

Generally no and I will tell you why.一般不会,我会告诉你原因。

What happens is that the browser is asking for a file that the web server can serve to the user.发生的情况是浏览器请求 Web 服务器可以为用户提供的文件。 The file has the extension .php for example.例如,该文件的扩展名为 .php。 The web server is setup so whenever he gets a request for a file with that extension he has to run it through PHP first and use the output from PHP as the output to serve the user. Web 服务器已设置好,因此每当他收到对具有该扩展名的文件的请求时,他必须首先通过 PHP 运行它,然后使用 PHP 的输出作为输出来为用户提供服务。

So the user asks for a file, the web server finds it, sees that PHP has to process it first, PHP does and gives the web server the output (whatever it is) and the web server then gives the user that content.因此,用户请求一个文件,Web 服务器找到它,看到 PHP 必须首先处理它,PHP 这样做并将输出(无论它是什么)提供给 Web 服务器,然后 Web 服务器向用户提供该内容。

It can happen that the web server is configured in the wrong way and skips the PHP step, so then the user sees pure PHP but this is very rare and usually spotted immediately. Web 服务器可能以错误的方式配置并跳过 PHP 步骤,因此用户会看到纯 PHP,但这种情况非常罕见,通常会立即发现。

absolutely no way.绝对没有办法。 PHP is processed before being outputted to the browser so its all server side! PHP 在输出到浏览器之前被处理,所以它的所有服务器端!

Hypertext pre processor is interpreter which understand the code and convert into html form with the help of webserver so it is not able to view on webserver超文本预处理器是解释器,它在网络服务器的帮助下理解代码并转换为 html 格式,因此not在网络服务器上查看
But on local machine without Webserver we can see the code但是在没有 Webserver 的本地机器上我们可以看到代码

如果文件扩展名为 .phps,您只能查看代码

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

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