How to Build a Simple Website With PHP
- 1). Create your website homepage by opening a new file in a text editor and saving it "index.php" entering the following outline code:
<html>
<head>
</head>
<body>
<?php
//php code here
?>
</body>
</html>
This is the basic outline of a Web page using PHP and HTML code. When people visit a website homepage, the server sends whatever is in the "index" file, so when your website domain name is entered into a Web browser address bar, this is the script that will run. - 2). Enter PHP code in your page, as follows (after the "php code here" line):
//get text representation of the date
$today = date("l jS F Y");
//write as HTML
echo "<p>Today is ".$today."</p>";
This simple example demonstrates the basic principle of using PHP code to perform processing and present the result in HTML. When the page is requested by the user's browser, the server will run the code contained within it, and send the results back to the browser for viewing. Connecting to a database is another common task for PHP pages. - 3). Create additional pages in your PHP website and link between them. Most websites consist of more than one page, so create however many pages you need using the same basic technique for building each in PHP, saving your pages with the PHP extension and appropriate names. For example "about.php" could be used for a page containing information about the site. Create links between the pages as follows:
<a href="/links/?u=about.php" title="about">About</a>
This anchor HTML could be included on the index page and any other pages, creating a link to the "about" information. Add whatever content you need in each page, including text, images and other media. - 4). Use Cascading Style Sheets to style your website. In your page head sections, add a link to a CSS file, as follows:
<head>
<link rel="stylesheet" type="text/css" href="/links/?u=phpsitestyle.css" />
</head>
Create a new file in a text editor for your CSS code, saving it as "phpsitestyle.css" or any other name you prefer, entering code as in the following example:
body
{font-family: Arial, Helvetica, sans-serif;}
p
{color:#330000;}
You can dictate all aspects of appearance and layout for your PHP website within the CSS code. - 5). Upload your PHP, CSS and any other files you included, such as images, to your Web server. Test your site by browsing to the home page in your Web browser and make sure it functions correctly. As well as checking that the PHP code executes without error, make sure the resulting HTML code is well-formed. You can use a Web "validator" tool for free to highlight any errors in your website HTML markup. Fixing these errors will make your website's appearance more reliable across browsers.
Source...