.php 文件在 Chrome 中显示代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15213551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:47:51  来源:igfitidea点击:

.php file shows code in Chrome

phphtmllogindreamweaver

提问by Alex Stack

I have a register page I retrieved off of the following site. I downloaded the source code and extracted the file, finding the login.php. I open it in Adobe Dreamweaver CS3 which loads it and shows no code, but when I click Preview in Chrome, Chrome shows the entire files code, which is shown below. When I click Preview in iExplore, it does the same. Am I doing something wrong or is there something I don't have on my laptop? I have not put the rest of the code for the webpage because I feel it is irevelent as when I cut the php code out and tested it it the page shows. It is just when I insert the PHP code. After the PHP is the normal code that Dreamweaver places in at the start of a new HTML or PHP file.

我有一个从以下站点检索到的注册页面。我下载了源代码并解压缩了文件,找到了login.php. 我在加载它的 Adob​​e Dreamweaver CS3 中打开它并且不显示任何代码,但是当我在 Chrome 中单击预览时,Chrome 显示了整个文件代码,如下所示。当我在 iExplore 中单击“预览”时,它也会这样做。我做错了什么还是我的笔记本电脑上没有什么东西?我没有为网页添加其余的代码,因为我觉得它很有趣,因为当我剪掉 php 代码并对其进行测试时,页面显示。就在我插入 PHP 代码时。PHP 之后是 Dreamweaver 放置在新 HTML 或 PHP 文件开头的普通代码。

<?PHP
require_once("./include/membersite_config.php");

if(isset($_POST['submitted']))
{
   if($fgmembersite->Login())
   {
    $fgmembersite->RedirectToURL("login-home.php");
   }
}

   ?>

回答by niaccurshi

To display PHP on your computer you need to have a local PHP server set up. Without it there is no PHP engine that can interpret and parse your code to make it in to HTML for the browser.

要在您的计算机上显示 PHP,您需要设置本地 PHP 服务器。没有它,就没有 PHP 引擎可以解释和解析您的代码以将其转换为 HTML 以供浏览器使用。

If you haven't got a PHP server installed locally, then you will need to upload your files to a server via FTP, where PHP is installed.

如果您没有在本地安装 PHP 服务器,那么您需要通过 FTP 将文件上传到安装了 PHP 的服务器。

回答by Kamil

PHP file must be interpreted by web server (you may use XAMPP, which is popular set of servers for Windows including Apache HTTP server, MySQL database server and PHP extension for Apache).

PHP 文件必须由 Web 服务器解释(您可以使用 XAMPP,它是 Windows 的流行服务器集,包括 Apache HTTP 服务器、MySQL 数据库服务器和 Apache 的 PHP 扩展)。

Server executes PHP code and sends script output/result via http protocol to web browser.

服务器执行 PHP 代码并通过 http 协议将脚本输出/结果发送到 Web 浏览器。

Opening that file via filesystem is bad idea, because PHP file will be read as plain text if it is not processed by web server with PHP.

通过文件系统打开该文件是个坏主意,因为如果 Web 服务器不使用 PHP 处理 PHP 文件,它将被读取为纯文本。

It looks like, you dont understand how PHP works. You need to read some books about web fundamentals.

看起来,您不了解 PHP 的工作原理。您需要阅读一些有关网络基础知识的书籍。

Eventually you can visit http://thenewboston.orgor http://phpacademy.org- they have very good educational videos.

最后,您可以访问http://thenewboston.orghttp://phpacademy.org- 他们有非常好的教育视频。

One more advice to consider:

另一个需要考虑的建议:

In my personal opinion Dreamwaver is very bad tool for learning PHP. For learning purposes I recommend to use Notepad++ or some other IDE (maybe NetBeans PHP edition). It will help you to understand more.

在我个人看来,Dreamwaver 是学习 PHP 的非常糟糕的工具。出于学习目的,我建议使用 Notepad++ 或其他一些 IDE(可能是 NetBeans PHP 版本)。它会帮助你了解更多。

How to debug php code in dreamweaver cs5?

如何在 Dreamweaver cs5 中调试 php 代码?

回答by CrazyCrisUk

You'll need a local web server with a PHP interpreter to parse the PHP code. There are a few to choose from. I personally use WAMP. Once it is installed place your php files in wamps www folder and browse to it in your browser using http://127.0.0.1/yourphpfilename.php

您需要一个带有 PHP 解释器的本地 Web 服务器来解析 PHP 代码。有几个可供选择。我个人使用 WAMP。安装后,将您的 php 文件放在 wamps www 文件夹中,然后使用浏览器浏览到它http://127.0.0.1/yourphpfilename.php

It should display the php output instead of the code then.

它应该显示 php 输出而不是代码。

回答by IQW

For execute that type of files you must have Apache (Web Server) + PHP (interpreter). It will be resolved by using something like XAMPP (you can google it.)

要执行该类型的文件,您必须拥有 Apache(Web 服务器)+ PHP(解释器)。它将通过使用类似 XAMPP 的东西来解决(你可以谷歌它。)