Skip to main content

PHP Tutorial - Lesson 2: Introduction to PHP - Part III


Server Side Includes (SSI)

          In order to organize your work, and be a professional programmer, simplify your code. There are many things you could do, to organize your code, and facilitate development acceleration to your application.
          Here I’ll put some advices to you as a programmer that might help you in your job.
          First thing, simplify, and simplify… Make it easy. Your script should do only one job. This will facilitate handling errors.
          Second thing, it is not preferred that your function has more than three parameters to finish its job, this means that you can simplify it more.
          Use Loops only when needed.
          Don’t repeat your code.
          Divide your script in directories, and group codes that complete each other in the same directory.
          Use available (OPEN SOURCE Libraries) rather than build it yourself. This will save your time, and give your application more qualities. Remember “Don’t re-invent the wheels”.
          Finally, think of simplest and shortest ways to do your mission. Of course it should be legal methods.

          Suppose that in your application, there is a menu that you need to be showed in more than one page. Of course, you have not to copy and paste the menu in every page. What about if you want to add a new item to your menu? Shall you add to all pages copying and pasting!! It is not a programming idea.
          The best and logical thing is put your menu in a file, and call this file where needed.
How to accomplish this?
          Save your menu in a file.
          For example “menu.php”.
          At each page you need your menu to appear, call the file by using one of these two functions include() or require().
          Both functions are identical in their job, but, they differ in handling errors. include function will search for your file, if found it then will be included in your page, and so require. But if not found. If you used include, your script will continue working, and will not stop. Where require will show an error and your script completely will not work.
Example
<?php
require(“menu.php”);
include(“wrong.php”);
?>
          If menu is found, the script will continue working, but wrong file will not stop working your script.
          Where to use?
          If your script depends completely on the included file, then use require. Else use include.
          In my opinion, I prefer require.
End of Lesson 2.
To download this lesson as PDF click here: PHP Tutorial - Lesson 2: Introduction to PHP - Part III

Best Wishes,
Anas Jaghoub 

Comments

Popular posts from this blog

PHP Tutorial–Guest Book–System Definition and Requirements

In this lesson I’m going to illustrate the system definition and requirements for the Guest Book application. It is an important step in developing any application, since this step gives us an orientation about the system and its functionality, what is expected from the system to do. actually the system definition comes from keywords from customers and end users, usually try to make it clear for what they need in the application, and what they expect the system to do.  As developers it is our role to define the requirements for the system to be developed. In our example the system definition for the Guest Book is: A system that allows visitors of the site to post their comments and feedbacks about the site, with the possibility for managing comments and maintain it easily and user friendly. On the other hand, the system requirements are: a web server, since it is clear that the developed system is going to run on the Internet, so it is a web-based application not windows-based.

Web Development Best Practices (PHP Best Practices)

Websites development is one of the most challenging projects ever to develop, according to the large number of components you deal with, integrate, and manage in your application. For example, most web projects Deal with databases as their data source, and I ntegrate with external services called web services and APIs. As well the application M anages its own objects and components from views to models to controllers to plugins and so on. A skilled web developer should have a great/deep knowledge in most of components used in his system, and as well should ha ve intensive focus on how each component work and how can be used, what can be done, and what cannot. On the other hand, the huge amount of requirements, components to manage, and time frame given to you to accomplish your mission, and number of people in your team, all these factors together requires from you to organize your tasks, and priorities your requirements, do deep analysis and planning in order to have a hi

Welcome To my blog :)

Hi all, I'm glad to start blogging here, to keep close to all of those who are interested in technologies in general, and specially programming and developing softwares. From this area, I'm going to share my little experience in developing windows based applications using C# .Net, and web based applications using PHP and ASP.Net.  There'll be lessons and trainings on programming and developing softwares.  Hope you all come and share us with your knowledge and experience, so we'll share knowledge. We all here believe that knowledge for all, and work for that. come and be part of this.  If you want to share us with your knowledge and experience in any topics related to programming and developing softwares, don't hesitate to contact us and start the trip.  Best Regards,  Anas Jaghoub