How to Build a PHP Web Site

A website with PHP has several advantages when compared to a static, HTML website. Coding with PHP saves time because of several built-in functions, such as "include," which allows you to create one set of document headers and footers that will appear on following webpages. PHP also has the ability to process form data, allowing the owner of the website a way to communicate with his/her audience. PHP, however, cannot take the place of HTML. It is a server-side scripting language. You still need to use HTML to build the website, but PHP can make it more efficient.

Things You'll Need

  • A text editor, like Source Edit
  • Document Uploading Software, like FileZilla
  • Space on a webserver
Show More

Instructions

    • 1

      Create the following folders on your server: images, header, and footer.

    • 2
      Header Code Image

      To create the header, open a new document in your text editor and save it as header.php. Type the following information:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

      <head>
      <title></title>
      </head>
      <body>

      Save the document and upload it to the header folder on your server.

    • 3
      Footer Code Image

      To create the footer, open a new document in your text editor and save the document as footer.php.

      Type the following:
      </body>
      </html>

      Save the document and upload it to the footer folder on your server.

    • 4

      To create the index page, open a new document in your text editor and name it index.php.
      Type the following information:
      <?php
      include('header/header.php');
      ?>

      First, establish that you will be coding in PHP by creating the beginning tag for PHP, which is <?php. Then add a PHP function, called "include," which will pull the document called header.php into the index.php file. Within the parentheses you must enclose the file's path and the file name in single quotes. End the statement with a semicolon. End the PHP code by typing the end PHP tag, which is ?>.

      Skip several lines and type the following:
      <?php
      include('footer/footer.php');
      ?>
      Follow the same sequence with the footer. The space between these two statements will be the content of the page, which will be written in HTML.

      You have just created the first page of your website. This is where the search engines will first land when crawling the World Wide Web. Save the changes to this document.

    • 5

      To create the navigation, open the header.php file. Add the following after the <body> tag:

      <table>
      <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      </tr>
      </table>

      This is an HTML table. The <tr> tag indicates that you are establishing a row of data. The <td> tags are the actual cells or columns of the cell. The pages where the end-user will eventually navigate will appear between the two tags <td> and </td>.

    • 6

      To populate the navigation, hit "Enter" after the body tag and before the <table> tag on the header.php file.
      Type the opening and closing PHP tags:

      <?php

      ?>

      Create the following variable and type it between the opening and closing PHP tags:
      $url = "http://www.yoursite.com";

      Substitute "yoursite" with your domain.

      Between the <td></td> tags, enter the following:
      <a href="<?php echo $url; ?>/index.php">Home</a>

      This is your first link. Type "Page 2," "Page 3" and "Page 4" between the three remaining <td></td> tags as place holders. Substitute the actual link and page information when you build the actual pages.

      Add the attribute border="1" to the beginning <table> tag so you can see your navigation table. Set the border to "0" if you wish to turn it off, i.e. <table border="1">

    • 7

      Upload index.php and header.php files to your server and test the link to make sure that there are no errors.

      Make sure that you upload the header.php file into your header folder.

    • 8

      Now that the rudimentary navigation is in place, you can begin to add some structure to your website, such as headings. I recommend organizing your page with <h1></h1>, <h2></h2> and <h3></h3> tags. The "h" in the <h1></h1> tags stand for "header." The numbers determine the overall importance, beginning with "1."

      Add a title to your page like this:
      <h1>This is my Homepage!</h1>

      Place this code after the </table> tag as shown in the image. Upload the index.php file to your server.

    • 9

      You can make subsequent pages.
      Open a new document in your text editor and save it as page2.php.

      Add the following code to your website, as you did to the file index.php:

      <?php
      include('header/header.php');
      ?>

      <h1>Page Two</h1>

      <?php
      include('footer/footer.php');
      ?>

    • 10

      In the header.php file, add the anchor tag around the words "Page 2" as shown:

      <td><a href="<?php echo $url; ?>/page2.php">Page 2</a></td>

      Upload the page2.php and header.php files to the server.

    • 11

      Preview in a browser. Page 2 should look like the image below.

    • 12

      Fill pages 2, 3 and 4 with content that supports the index.php page. Update the navigation to reflect their specific page names. This should get you on your way to building your own PHP website.

      A PHP-based website allows you to create a template system to avoid retyping repetitive code. It can make your coding quicker and focuses website construction on unique tasks versus repetitive tasks.

Tips & Warnings

  • • Always test your code to make sure that it works as intended. Don't assume that your typing is perfect. You could easily add a colon versus a semicolon, which will prevent your page from loading properly.

  • • I recommend FileZilla, which is a piece of software designed to upload documents to your server. It is free to download. Here is the link: http://filezilla-project.org/download.php

  • • I also recommend Source Edit as your text editor. The benefit of using Source Edit, versus Notepad is that the lines are numbered, and if you have made an error, you can jump down to the specific line that PHP references. It is free to download. Here is the link: http://www.brixoft.net/download.asp#ID1

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured