.php file shows code in Chrome [closed]

2020-02-14 06:37发布

问题:

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 6 years ago.

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.

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

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

   ?>

回答1:

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.

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.



回答2:

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

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



回答3:

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).

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

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.

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

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

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.

How to debug php code in dreamweaver cs5?



回答4:

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.)