/    Sign up×
Community /Pin to ProfileBookmark

Website Structure

I’m new to PHP and I’m wondering how to structure my website. My site will consist of 7 pages total. I’ve done some research and found that most PHP sites use a pyramid structure where each directory has its own index.php page. Is this really required when the number of pages will not change? What’s the benefit of doing this? And are there any drawback to just placing each page in the root directory?

Also, I’m a bit confused as to how navigation with variables is handled in PHP site. For example, a homepage will be: “http://www.somesite.com/index.php?option=com_frontpage&Itemid=1” and the “contact” page will be “http://www.somesite.com/index.php?option=com_contact&Itemid=3“. I guess I dont understand what goes on in the background. What do the variables point to? Is the second page actually still the index.php page? How does it all work?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@DaveSWDec 05.2007 — Firstly you haven't mentioned what database system you're using that has these variables...

Personally if I was creating a 7 page website I would just make it in html, and then use the php include command to include any repeated code - i.e. menu, top header graphics etc.

If you're using a database for some reason like end user editing, then it makes sense to use a system like the one you're using. Anyway, that's your choice, there is no 'right or wrong way', it's entirely up to you and what you're comfortable with.

your index.php page will include a few lines of code that look at the variables transferred in the url (the get method) and then look into your database for an itemid of x (1) and a name of y (or frontpage). If it finds these then it will open another field in the database like 'content' which contains the actual content for that page. It will then write this into the page.

e.g. your database could look like:

Itemid, com, content;

1, Frontpage, Welcome to my frontpage;

3, contact, To get in touch call...;

So your one index.php file will change depending on the variables you pass to it.

Does that sort of make sense?

Dave
Copy linkTweet thisAlerts:
@spyder84authorDec 05.2007 — Using html pages made more sense to me as well. The reason I wanted to use PHP was to take advantage of the include command and also integrate a PHP emailer into my site. I was under the impression that any website that makes use of PHP script needed to contain only *.php files. But it seems that is not the case. Also in the future, I'd like to use a simple database (mySQL) to store articles which I would allow users to view.
Copy linkTweet thisAlerts:
@holidayDec 06.2007 — I normally use separate files in the root of my site. Like index.php, contact.php, about.php, search.php and etc... and then just include common files.

PS that's how facebook does it ;-)
Copy linkTweet thisAlerts:
@DaveSWDec 09.2007 — If I'm doing an online shop then I would have index.php, products.php, product.php, contact.php etc.

Then the products.php displays whatever category is passed to it, whilst product.php displays only the selected product.

The choice really is whether you have one template, and include the individual page code via get variables as you show above, or whether you create the individual pages and include common content such as menus and headers etc.

Whatever works for you ;-)
×

Success!

Help @spyder84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...