PHP Sessions

Why you’ll use session?

From the PHP cookie lesson, you learnt that after web server sends back the file the browser asked for, the transaction completes and both web browser and web server forget about that. Like cookie, session is used to keep track of what a visitor is doing, which pages he is browsing, which items he is selecting in the cart etc. Continue reading PHP Sessions

PHP Variable Scope

The part of a script where a variable is accessible after it is declared is its scope. Not always a variable could be accessed after it’s been declared in the remaining part of the script. The location of declaration determines scope of the variable.

Depending on the existence of function in a script, the scope can be divided into 2 parts-

  1. Local scope/ function scope: Local or function scope begins from the function declaration to the closing brace at the end of the function.
  2. Global scope: Other than the local scope, the remaining parts of the function are included in the global scope. Continue reading PHP Variable Scope

PHP Functions

Why function is necessary?

In your project, sometimes you need to perform same task multiple times. Therefore, you need to write the same code every time it requires. It makes programming time consuming, boring, and tedious. To make development easier, a programming feature named function comes to rescue in this stage. You can define the set of statements that perform a single task once as a function and call it by its name whenever you need. Continue reading PHP Functions

PHP File-Inclusion

Up to this point, the php scripts we’ve written in this course are fairly simple and short. But, real world project is different. When you develop a large website, you’ll find that same codes are being used again and again in different scripts. For example, most pages in a website have common header, footer, and navigation menus. In this case, should you copy and paste the same header code in every page? Continue reading PHP File-Inclusion