Server Topic
   >  Introduction to Webservers
   >  Installing the Webserver
   >  Controlling the Webserver
   >  Installing PHP Support
   >  Using PHP
   >  Installing mySQL Database
   >  Using mySQL

 

How to Use PHP

How to use PHP in your Web Pages

There are plenty of great PHP tutorials out there, so we are not going to cover PHP in detail here. Instead, we aim to convey the basic idea of how it works and leave you to explore the references below.

When the user requests a file with a .php extension, the PHP pre-processor scans the file for any PHP tags and executes any code within them; the results are substituted into the file in place of the tags and the resulting page is then sent to the client browse

PHP works by embedding commands (-wrapped in PHP tags) in an otherwise static web page (-such as HTML) of the format:

<?php .... php commands .... ?>

The file is then given a .php extension and saved within the web root (-defined in the lighttpd.conf file by the "server.document-root" directive) on the server. When the user requests a file with a .php extension, the PHP pre-processor scans the file for any PHP tags and executes any code within them; any results are substituted into the file in place of the tags and the resulting page is then sent to the client browser.

Here is a trivial PHP file:

<HTML>
<HEAD>
          <TITLE>
           <?php 
                 $pageTitle = 'This is a Test Page';
                 echo $pageTitle;
            ?>
            </TITLE>
</HEAD>
      <h2><?php echo $pageTitle ?></h2>
      This is a simple PHP file
<BODY>

</BODY>
</HTML>

After passing through the PHP pre-processor, the final document returned to the client browser would be equivalent to the following static HTML:

<HTML>
<HEAD>
        <TITLE>
        This is a Test Page
        </TITLE>
</HEAD>
      <h2>This is a Test Page</h2>
      This is a simple PHP file
<BODY>

</BODY>
</HTML>

References and Further Reading:


HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button