简体   繁体   中英

PHP code printing as plain text instead of executing

I'm doing a chrome extension tutorial . The pop.html file has a POST form that connects to a php file called script.php. When I open script.php in the browser, the code executes an echo statement for testing purposes. However, when I run the chrome extension, I fill out the form and click the "submit" button, but instead of executing the code in script.php, it simply prints the code in script.php as plain text within the popup window.

Can anyone explain why the php code won't work for the extension? Throughout the day I've tried all the solutions described in the following posts: post1 post2 post3

Below are my files and code for reference.

In my MAMP directory, I have the following files in a project folder called "GlassExt":

manifest.json

 { "manifest_version": 2, "name": "Glass - Connect to Database", "description": "test database functionality", "browser_action":{ "default_title":"Hello, Yo!", "default_popup":"pop.html" }, "version": "1", "permissions": [ "http://localhost/*" ] } 

pop.html

(I previously had the "action" attribute set to " http://localhost/glassExt/script.php ", but for some reason the form would not submit at all.)

 <DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>This is a title, yo</title> </head> <body> <form action="script.php" method="POST"> <input type="text" name="name" placeholder="Your Name"><br> <input type="text" name="email" placeholder="Your Email"><br> <input type="submit" value="Go"> </form> </body> </html> 

script.php

 <?php $test = "this is a test"; echo $test ?> 

Chrome extension can't execute a php script. But you can try posting data to a server like following, but it will not be part of your chrome extension.

<form action="http://domain/script.php" method="POST">
    ...
</form>

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