简体   繁体   中英

Generating a webpage with cgi, containing both html and php

I'm trying to generate a webpage with cgi that contains both html and php.

When I directly type some basic code in a file "test.php", it works fine:

<html>
<body>
<h1> Hello world! </h1>
<?php phpinfo() ?>
</body>
</html>

When I generate only html code with an executable file "test.cgi" (located in cgi-bin), it also works fine:

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<body>"
echo "<h1> Hello world! </h1>"
echo "<html>"
echo "<body>"

But when I try to add a line of php, it doesn't work anymore:

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<body>"
echo "<h1> Hello world! </h1>"
echo "<?php phpinfo() ?>"
echo "<html>"
echo "<body>"

Only the html part is displayed. Any php seems to be neglected.

Some more information:
- Ubuntu 12.04
- PHP Version 5.3.10-1ubuntu3.4
- Apache2

Can somebody help me on this?

My understanding, and I hope somebody will correct me if I'm wrong, is that

  • CGI is a server-side-process language
  • PHP is a server-side-process language

but in each case, what it does is deliver HTML to the browser. CGI does not deliver its output back to the web server for re-processing as PHP code.

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