5 important steps to keep in mind when making a php site
First of all, I’d like to mention that this is not a post for an absolute beginner. This is more of a post for those who work with php and know their way around but who simply don’t know certain things about how you should make a php page. So, without further adu, the 5 important steps you should keep in mind when making a php site are:
1. Put all the essential data inside a config.php file. This way, you won’t have to rewrite the passwords and all the global variables inside each php file. And by global variables I mean those variables keep their value all over the site. If $var1 has the same value in index.php and gallery.php, why declair it twice?
What are the advantages of this? Well, if you need to change something, it will automatically change all over the site, so you won’t have to edit each file that uses those values.
2. Make all the parts of the site that remain the same all over the pages into separate php files. For example, make a header.php file, a footer.php file, a menu.php file and so on. It’s just like I said above: if you need, for example, to add an extra link in the menu, you’ll just have to edit the menu.php file and not all the pages that run the menu inside them.
This works for the cases where the html part is the same, but the content is different. But I’ll speak about it on the next step.
3. Keep separating files even if their content is different, as long as the structure is the same. For example, if your header will be the same all over the site, but it will have different keywords for each page, make a header.php file that will read it’s keywords from a mysql database. Depending on what page you are on, it will select different records from the database. If you’re wondering how to do it, the switch statement is a good answer.
4. This one is a more general statement. When you are making php sites, try to think the pages in manner where the code can do different things with different values. It’s good to decrease the sizes of a page. For example, I managed to combine 8 different pages into a single page that does everything those pages did, depending on the values it receives via the POST or the GET method.
5. Make your site portable. Don’t just think that you’ll only use it on that host for that specific reason. If you could easily move the site to another host and change it’s template and content, but keep the coding time, you could save yourself from a lot of effort. Basically, think of your site more like a CMS than a simple personal website.
You`re right! These are the most important steps for a php site! Keep up the good work!