I just built a small PHP based site from scratch, yay for me! But given the size of it, it's running a little slower than I expected.
I have the files/folders organized like this:
- articles [folder]
- css [folder]
- html [folder]
- images [folder]
- js [folder]
- photography [folder]
- resources [folder]
- articles.php [file]
- bio.php [file]
- contact.php [file]
- content.php [file]
- favicon.ico
- footer.php [file]
- header.php [file]
- index.php [file]
- photography.php [file]
And most of my PHP files are coded something like this:
<?php
$thisPage="Writing";
include("header.php");
$page = $_GET['article'];
$file = "articles/".$page.".html";
if(file_exists($file)) {
include($file);
} else {
print "404 Error. Page does not exist";
}
function IsSafeInclude($x) {
if(strpos($x, "/../") !== false || strpos($x, "../") === 0 || strpos($x, "/..") == (strlen($x) - 3) || $x == '..')
return false;
else
return true;
}
//include("html/articles-left.html");
?>
<div id="article-nav-container">
<ul id="article-nav-pg">
<li><a href="articles.php?article=article_name1">1</a></li>
<li><a href="articles.php?article=article_name2">2</a></li>
<li><a href="articles.php?article=article_name3">3</a></li>
<li><a href="articles.php?article=article_name4">4</a></li>
<li><a href="articles.php?article=article_name5">5</a></li>
<li><a href="articles.php?article=article_name6">6</a></li>
</ul>
<script type="text/javascript">
$(document).ready(function() {
var loc = window.location.href; // The URL of the page we're looking at
$('#article-nav-pg a').each(function() {
if (loc.indexOf(this.href) !== -1) { // If the URL contains the href of the anchor
$(this).addClass('selected'); // Mark it as selected
}
});
});
</script>
</div><!-- end articles nav -->
<p id="left-description"><img src="images/side-descrip-stories.jpg" width="20" height="90" alt="Story Description" /></p>
<?php
include("footer.php");
?>
Some files also have html codes directly inside. I would appreciate any advice on how to improve the speed on my small PHP based site.
Thanks