Skip to content

Commit 15c91ac

Browse files
committed
Version 1.0
0 parents commit 15c91ac

File tree

8 files changed

+97
-0
lines changed

8 files changed

+97
-0
lines changed

functions.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* Used to store different static data.
5+
*
6+
* @var array
7+
*/
8+
$config = [
9+
'name' => 'Simple PHP Website',
10+
];
11+
12+
/**
13+
* Displays site name. Uses $config global.
14+
*/
15+
function siteName()
16+
{
17+
global $config;
18+
echo $config['name'];
19+
}
20+
21+
/**
22+
* Displays page title. It takes the data from
23+
* URL, it replaces the hyphens with spaces and
24+
* it capitalizes the words.
25+
*/
26+
function pageTitle()
27+
{
28+
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'home';
29+
30+
echo ucwords(str_replace('-', ' ', $page));
31+
}
32+
33+
/**
34+
* Displays page content. It takes the data from
35+
* the static pages inside the pages/ directory.
36+
* When not found, display the 404 error page.
37+
*/
38+
function pageContent()
39+
{
40+
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
41+
42+
$path = getcwd().'/pages/'.$page.'.php';
43+
44+
if (file_exists($path)) {
45+
include $path;
46+
} else {
47+
include 'pages/404.php';
48+
}
49+
}

index.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php require 'functions.php'; ?>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf-8" />
6+
<title><?php siteName(); ?> | <?php pageTitle(); ?></title>
7+
<style type="text/css">
8+
.wrap { max-width: 700px; margin: 50px auto; padding: 30px; text-align: center; box-shadow: 0 0 5px rgba(0,0,0,.5); }
9+
article { text-align: left; padding: 40px; }
10+
</style>
11+
</head>
12+
<body>
13+
<div class="wrap">
14+
15+
<header>
16+
<h2><?php siteName(); ?></h2>
17+
<nav class="menu">
18+
<a href="/" title="Home">Home</a> |
19+
<a href="/?page=about-us">About</a> |
20+
<a href="/?page=products">Products</a> |
21+
<a href="/?page=contact-us">Contact</a>
22+
</nav>
23+
</header>
24+
25+
<article>
26+
<h3><?php pageTitle(); ?></h3>
27+
<?php pageContent(); ?>
28+
</article>
29+
30+
<footer><small>&copy;<?php echo date('Y'); ?> <?php siteName(); ?>. All rights reserved.</small></footer>
31+
</div>
32+
</body>
33+
</html>

pages/404.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>404 - This page does not exist.</p>

pages/about-us.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>about</b> page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
2+
</p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>

pages/contact-us.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>contact</b> page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
2+
</p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>

pages/home.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>home</b> page.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
2+
</p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>

pages/products.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>product</b> page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
2+
</p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Simple PHP Website
2+
3+
I put together this porject why introducing to PHP a good friend of mine. I decided to clean it up a bit and put it
4+
on Github so anyone new to PHP can have a taste of a very simple and minimal site in PHP.
5+
6+
MIT License

0 commit comments

Comments
 (0)