user1824693
user1824693

Reputation: 13

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?

Upvotes: 1

Views: 91

Answers (1)

hymie
hymie

Reputation: 2068

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.

Upvotes: 1

Related Questions