I am a beginner PHP developer and web designer. I want to know which is most efficient.
In school I learned to build sites in HTML 4 strict and using php ‘includes’ in order to avoid re-typing things over and over. So I would make the head of the document head.php and include it at the beginning of all the files. Each file extension would be .php even if it was just a page of HTML content because there were php includes inside it. Links would send the browser from page to page.
Now I am making this new website which is a re-design of a clients’ old website. It was done using tables for layout and all this horrible inline CSS and presentation and semantics all mixed together.
Now instead of doing it like I learned in school, I wanted to keep all the content pages .html instead of .php because my client likes to update his content using dreamweaver and for some reason you can only preview stuff in DW when there is an .html file extension. Whatever, I hate dreamweaver but he uses it. I also wanted to separate content from scripting so I wanted .php files to have PHP code and website content to be in .html files.
To achieve this I made an index.php page with a lot of conditional includes in the right places. So, instead of the user navigating from page to page, the user clicks on links and they direct the browser back to index.php but with a different query string. Depending on the query strings, the index.php files has different .html files included into it.
Is this a bad-practice way to do things? Also, is it a SEO friendly way of doing things? I never really took this idea from anywhere; it just seemed like a logical way to keep HTML in .html files and PHP in .php files. What is the best topic to read up on if I want to learn on best-practice ways to build more complex sites? Doing it this way seems to be working fine; the site which is fairly large works and looks good, but I’m worried about how SEO friendly it is and how difficult or easy it is to maintain in the long-term. Thanks very much
You can set your server to process .html files as .php files, it can be done as a setting in apache.
This is known as a page-controller (I think) I used this method for years and years, not knowing any better. While it held some benefits initially, mainly that just about everything was in one place, it quickly became a nightmare to debug and manage and I would dread having to open them up and add or adjust functionality.
It was about then that I started to learn about OOP - although it is not necessary to do so - mainly because I suspected there was more code I could be sharing amongst pages.
Learning OOP inevitably leads you to learning about “layering” your application and as you say, separating concerns typified as html and php in your problem.
You could think of the adoption of OOP as a one-up move from just including content - but it would be kind of missing many beneficial points - the easiest of which to grasp would probably be avoiding namespace clashes, You know, you have a variable called $page which when used suddenly wipes out an old variable called $page which you had simply forgotten about.
The above is not very SEO or people friendly, but this is:
Quite simply - to carry on as you are, leave your page controllers as they are and achieve the above SEO improvement then you could simply learn about apache’s mod_rewrite
It would be nice to think my words made sense, but overall it was just an awareness that I was repeating myself and it was wasteful, and that surely other people smarter than me were finding and talking about better ways of doing things.
It is probably not coincidental that it was around this time ** that I joined the SP community and started to try and help other users, and in doing so found out just how little I actually did know. Its humbling and painful sometimes, but boy oh boy, do you LEARN from some smart people.
Go on, stick your neck out.
**Cups is my 3rd user name, the others having been abandoned after they disgraced themselves after AFD-style rants and attacks
Thank you very much for the guideline you have provided to me but I think so that the beginners should use some other reference books before starting the programming because its not really hit and trail method. We should aware of what we are going to do. Anyways thanks for help.
Thanks for the help. That makes a lot of sense. I’m noticing the same feelings that you described from your past; that once the site becomes more complex adding content and functionality starts to become complicated and tangled and daunting.
I think I will learn to use mod_rewrite to make nice URLS and I’ll look into OOP so that there is one object that loads content into placeholders etc.