Search code examples
phphtmlframeworksheaderfooter

What is the best way to set up a simple website?


I have been making websites for years now. Most of them tend to be under 10 pages and don't require any programming at all. I am wondering if anyone with lots of experience can recommend the standard or best way to go about setting up these types of websites. Let me explain in a bit more detail what I mean.

Here is a typical structure of one of the websites I have made in the past.

/css
/images
/js
/html
/html/about.html
header.php
footer.php
index.php

In this case, my index.php includes the header.php file at the top and the footer.php file at the bottom and I use PHP's switch function to handle the different cases for the content that I would like to view. For example, I might see index.php?z=about in the URL bar and my index.php will look for a file called about.html in /html

I know this all seems a little dumb to ask since is there really a best way to go about doing this?

Depending on the page, one of my main navigation items will have an "active" class. The work is done in PHP but I wonder if using javascript would be a better solution.

I'll appreciate any replies, thanks.


Solution

  • Just a few things off the top of my head:

    • Yes, stick with PHP for the active class. Some people have JavaScript disabled.
    • You might want to use URL rewriting to de-uglify the URLs. (ex. http://www.example.com/about in the URL bar gets rewritten on the server to http://www.example.com/index.php?z=about)
    • If the site gets bigger, you might want to use a database instead of files in a folder.
    • I'd put header.php and footer.php either outside of the document root or in an includes folder that disallows access to it with a 403 Forbidden error.