Enter your Sign on user name and password.

Forgot password?
Sign In | Sign Up
Start learning today, and be successful in your academic & professional career. Start Today!

Use Chrome browser to play professor video
Matthew M.

Matthew M.

Include Files & Web Application Introduction

Slide Duration:

Table of Contents

Course Introduction

12m 13s

Intro
0:00
What Is PHP?
0:12
PHP Hypertext Preprocessor
0:13
Why Learn PHP?
1:09
Why Learn PHP?
1:10
Web Application: Educator Store
2:25
Web Application: Educator Store
2:26
Example of Web Application
3:18
PHP in the Educator Store
7:12
Dynamic Content Generation
7:22
Ease of Website Maintenance
7:55
Form Input Processing and Access to Advanced Functionality
9:00
What You Will Learn
9:36
What You Will Learn
9:37
Who Is This Course For?
10:56
Who Is This Course For?
10:57
How PHP & The Web Work

15m 32s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Client-Server Model
0:53
Client-Server Model
0:54
HTTP Protocol
2:15
Definition of Protocol
2:16
Hypertext Transfer Protocol (HTTP)
2:37
Uniform Resource Locators
3:46
Uniform Resource Locators (URLs)
3:47
Form of URLs
4:13
Accessing Webpages with URLs
5:13
Serving Webpages
6:14
Serving Webpages, Client Machine, and Server Machine
6:15
Static vs. Dynamic Webpages
8:30
Static Webpage
8:31
Dynamic Webpage
8:55
Server-Side Scripting
9:54
Server-Side Scripting
9:55
Static and Dynamic Webpage Coding Example
11:17
Static and Dynamic Webpage Coding Example
11:18
Serving Dynamic Webpages
13:07
Serving Dynamic Webpages
13:08
Setting Up Your Development Environment

33m 11s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Development Environments
1:04
Development Environments
1:05
Our Default Development Environment: Window 7
1:54
Remote Development
4:04
Development Machine & Remote Server
4:05
Local Development
6:54
Development Machine
6:55
Software Used In This Course
9:41
Firefox Web Browser & Firebug Add-On
9:42
XAMPP
12:15
PSPAD Text Editor
13:16
XAMPP Installation
13:49
XAMPP Installation
13:50
Verify XAMPP Install
16:26
Verify XAMPP Install
16:27
localhost
19:08
localhost and 127.0.0.1 'loopback' IP Address
19:09
Document Root
21:16
Document Root and Directory Name
21:17
Document Root for Apache in XAMPP: htdocs & Example
22:13
Text Editor Spectrum
26:12
Text Editor Spectrum: Barebones to IDE
26:13
PSPad & Example
27:02
Finding Help
30:26
Web Resources
30:27
Homework Challenge
31:36
Homework Challenge
31:37
Homework Challenge (cont.)
32:38
Homework Challenge (cont.)
32:39
Your First PHP Script

12m 41s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
.php To HTML
1:00
.php To HTML
1:01
PHP Delimiters
2:20
PHP Delimiters: Opening & Closing PHP Tags
2:21
'Hello, World!' Example
4:34
Echo Statement & PHP Tags
4:35
Adding Second Heading
7:34
Homework Challenge
9:56
Homework Challenge
9:57
Basic PHP Syntax

40m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
PHP Delimiters
0:38
Long and Script Form
0:39
Short and ASP Style
1:33
Example
2:01
php.ini: PHP's Configuration
3:40
php.ini
3:41
Configuration Directives
3:48
Short and ASP Style: Enabled/Disabled
4:13
phpinfo()
7:58
Statements
14:28
PHP Statements
14:29
Example: PHP Statements
14:55
Comments
16:53
PHP Comments
16:55
Single-line Comments
17:37
Multi-line Comments
18:13
Example: PHP Comments
18:47
Coding Conventions
24:26
Coding Conventions
24:27
Example: PHP Coding Conventions
26:19
Homework Challenge #1
33:51
Homework Challenge #1
33:52
Homework Challenge #1 (cont.)
35:41
Homework Challenge #1 (cont.)
35:42
Homework Challenge #2
36:09
Homework Challenge #2
36:10
Homework Challenge #2 (cont.)
38:07
Homework Challenge #2 (cont.)
38:08
Variables & Numeric Data Types

16m 38s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:12
Working With Data
0:48
8 Types of Data for PHP
0:49
Identifiers
1:40
Identifiers: Definition and Example
1:41
Variables
2:47
Variables Definition
2:48
Variables Syntax
3:06
Integer Data Type
4:44
Integer Data Type
4:45
Integer Literals
5:08
Examples
5:30
Float Data Type
6:26
Float Data Type
6:27
Float Literals
7:00
Example
7:21
Example: PHP Code Declaring Variables
8:06
Example: PHP Code Declaring Variables
8:07
var_dump() Function
9:59
var_dump()
10:00
Example: Code and Output
10:30
Example: var_dump() Function
11:19
Coding Conventions: Variables
12:32
Lower Camel Case Notation
12:33
Variable Name Lengths
13:54
Homework Challenge
14:54
Homework Challenge
14:55
String Data Type

18m 6s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
String Data Type
0:29
String Data Type
0:30
Specifying String Literals
1:03
Single-Quoted Strings
1:53
Single-Quoted Strings
1:54
Escape Sequences
2:31
Escape Sequences
2:32
Example
2:46
Escape Sequences for Commonly Used Special Characters
4:32
Double-Quoted Strings
6:04
Double-Quoted Strings
6:05
Variable Interpolation
6:44
Coding Conventions: Strings
7:54
Coding Conventions: Strings
7:55
Homework Challenge
8:54
Homework Challenge
8:55
Include Files & Web Application Introduction

38m 43s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
include Statement
0:47
include Statement: Definition
0:48
Include Statement: Syntax
2:05
include Statement: Example
2:25
include Path
6:32
Absolute and Relative Path
6:34
Specified Path
7:15
Not Specified Path
7:55
Code Reuse
9:35
Code Reuse
9:36
Example
11:11
require Statement
12:56
require Statement: Definition
12:57
require Statement: Syntax
13:32
Include versus Require
13:52
Coding Conventions
16:33
Coding Conventions
16:34
Introduction to Our Web Application
20:32
Introduction to Our Web Application
20:33
Updating Web Application
21:14
Web Application Example
22:59
Homework Challenge
35:33
Homework Challenge
35:34
Homework Challenge (cont.)
37:38
Homework Challenge (cont.)
37:39
Arrays

34m

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is an Array?
0:42
What is an Array?
0:43
Arrays in PHP
1:44
Keys and Values
2:15
Types of Arrays
3:37
Indexed Arrays & Associative Arrays
3:38
array() Construct
6:47
Declaring Arrays
6:48
Defining Indexed Array
7:00
Defining Associative Arrays
7:43
Square Bracket Syntax
8:50
Square Bracket Syntax
8:51
Accessing Indexed Arrays
9:02
Accessing Associative Arrays
9:56
Arrays Example
10:41
Indexed Arrays Example
10:45
Associative Arrays Example
13:55
Multi-Dimensional Arrays
18:28
Multi-Dimensional Arrays
18:29
Multi-Dimensional Arrays Example
18:51
Multi-Dimensional Arrays in PHP File
20:34
Coding Conventions: Arrays
27:59
Coding Conventions: Arrays
28:00
Homework Challenge #1
29:20
Homework Challenge #1
29:21
Homework Challenge #2
30:38
Homework Challenge #2
30:39
Web Application Development

27m 38s

Intro
0:00
Versions
0:14
Version 3.0
1:23
Version 3.1
8:08
Version 3.2
11:42
Version 3.3
20:27
Homework Challenge
26:31
Homework Challenge
26:32
Script Input & The GET Method

30m 18s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Providing Input to PHP
0:39
GET Method, POST Method, and Cookies
0:40
Name/Value Pairs
1:22
GET Method
1:57
HTTP GET Method
1:58
Query String
2:52
GET Method Example
3:38
GET Method Example
3:39
Review of HTML Forms
8:16
HTML Forms
8:17
Input Control and Submitted Form
9:13
<form> Tag
10:07
<form> Tag
10:08
Method
10:34
Action
11:13
Input Control Examples
11:50
Input Control Examples
11:51
Common Input Controls
17:31
Common Input Controls
17:32
Query Strings
18:52
Query Strings
18:53
Query Strings Syntax
19:12
URL Encoding
20:01
URL Syntax
20:02
Examples
21:17
Simple Form Example
22:28
urlencode() Function
24:08
urlencode() Function
24:09
Example
25:03
urlEncoding Text Example
25:54
Simple Form Example
25:55
Homework Challenge
28:46
Homework Challenge
28:47
Accessing Form Data in PHP

32m 1s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
$_GET Array
0:48
$_GET Array
0:49
Accessing the Value of a Name/Value Pair Submitted Via GET
1:04
Name Form Example
2:54
Name Form and the $_GET Array
2:55
Using Arrays with Input Controls
6:34
Using Arrays with Input Controls
6:35
Common Example
6:47
Indexed Array Form Example
8:16
Indexed Array Form Example
8:17
Associative Arrays with Input Controls
10:14
Associative Arrays with Input Controls
10:15
Associative Arrays Example
11:41
Associative Arrays Example
11:42
Echo Form Example
15:18
Echo Form Example
15:19
Outputting Arrays In String
23:42
Variable Interpolation
23:43
Outputting a Value in an Indexed Array Within a String
24:12
Simple' Syntax, 'Complex' Syntax, and 'Curly Brace' Syntax
25:00
Outputting Arrays In String Example
26:25
Outputting Arrays In String Example
26:26
Homework Challenge
29:39
Homework Challenge
29:40
Web Application Development

20m 20s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
Version 3.3
0:38
Version 3.3
0:42
Version 4.0 Changelog
2:43
GET Query
2:45
Adding, Editing, and Removing
3:24
Version 4.0 Coding Example
3:55
item.php, itemID, and itemListing
4:00
Version 4.1 Changelog
10:36
Version 4.1 Changelog
10:37
Version 4.1 Coding Example
11:45
Adding Checkout and Thank You & Editing Footer and Store
11:46
Homework Challenge
18:45
Homework Challenge
18:46
Expression & Operators

31m 56s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Expressions
0:41
Expressions Definition
0:42
Example: Literals
0:55
Example: Variables
1:05
Operators
1:44
Operators Definition
1:45
Unary, Binary, and Ternary Operators
2:07
Assignment Operators
2:52
Assignment Operators
2:53
Array Assignment Operator
3:47
Arithmetic Operators
6:15
Operators for Common Arithmetic Operations
6:16
Modulus Operator
7:41
Arithmetic Operators Example
8:25
Increment/Decrement Operators
10:48
Increment/Decrement Operators
10:49
Pre- and Post- Increment/Decrement
12:43
Coding Example
15:14
Combined Assignment Operators
16:44
Combined Assignment Operators
16:45
Combined Assignment Operators Examples
18:23
Coding Example
19:39
String Operators
20:28
Concatenation Operator, String Variables, and String Literals
20:29
String Operators Example
22:41
Precedence & Associativity
23:40
Precedence & Associativity
23:41
Expression Containing Multiple Operations
23:58
Expression Containing Two Operations of Equal Precedence
25:55
Using Parentheses to Force Precedence
26:52
Precedence & Associativity Review
28:57
Homework Challenge
31:08
Homework Challenge
31:09
Web Application Development

20m 51s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Version 4.1 Review
0:33
Version 4.1 Review
0:34
Version 5.0 Changelog
1:05
Version 5.0 Changelog
1:06
Version 5.0 Example
2:19
Adding View Cart & Editing Checkout, Footer and Store
2:20
Version 5.1 Changelog
15:36
Version 5.1 Changelog
15:37
Version 5.1 Coding Example
17:33
Forwarding Order Total to Thank You Page
17:34
Homework Challenge
20:09
Homework Challenge
20:10
Boolean & Null Data Types

20m 11s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Boolean Data Type
0:38
Boolean Data Type
0:39
Two Boolean Literals
1:24
Boolean Example
1:50
Boolean Example
1:51
Comparison Operators
4:00
Comparison Operators Definition
4:01
Common Comparison Operators
4:40
Comparison Operators Example
6:49
Comparison Operators (Cont.)
10:10
Identical and Not Identical
10:11
Example: Identical and Not Identical
11:24
Null Data Type
13:36
Null Data Type Definition
13:37
Null Literal
14:08
Variable and Null Data Type
14:30
'==' Operator
15:24
Null Data Type Example
15:59
Coding Convention
18:41
Coding Convention
18:42
Homework Challenge
19:17
Homework Challenge
19:18
Type Casting

22m 41s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Type Juggling
0:54
Type Juggling
0:55
Automatic Conversion
2:23
Type Casting
3:53
Type Casting
3:54
Implicit and Explicit Type Casting
4:00
Explicitly 'cast' a Variable Example
4:16
Type Casting (cont.)
6:48
PHP Allows the Following Explicit Type Casts
6:49
The settype () Function
8:18
Type Casting Coding Example
9:00
Explicit Type Casts
9:01
String Conversions
14:52
String Conversions
15:05
Common Conversions to String
15:55
Numeric Conversions
18:18
Numeric Conversions
18:19
Boolean Conversions
20:29
Boolean Conversions
20:30
Homework Challenge
21:38
Homework Challenge
21:39
Introduction to Functions

52m 20s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
What are Functions?
0:51
Definition of Faction
0:52
PHP and Function Call
1:53
Function Calls
2:42
Function Calls
2:43
Function Arguments
3:17
Return Values
4:56
Return Values
4:57
Function Chaining
6:29
Function Chaining
6:30
PHP.net Function Reference
8:23
PHP.net & Function Prototypes
8:24
PHP.net Function Reference Example
9:29
Optional Function Arguments
12:28
Optional Function Arguments
12:29
String Functions
14:57
strtoupper() and strtolower()
14:58
implode (), str_replace(), explode(), strpos(), substr(), and strlen()
18:31
Array Functions
25:48
count()
25:49
in_array() and array_key_exists()
26:06
sort() and ksort()
26:37
Example: count() and in_array()
27:50
Example: array_key_exists()
29:53
Example: sort() and ksort()
31:20
Date & Time Functions
33:38
date() and time()
33:39
getdate()
34:49
mktime()
35:01
Date & Time Functions
35:12
Example: date() and time()
35:58
Example: getdate()
42:15
Example: mktime()
43:15
Homework Challenge #1
44:31
Homework Challenge #1
44:32
Homework Challenge #1 (Cont.)
45:28
Homework Challenge #1 (Cont.)
45:29
Homework Challenge #2
46:34
Homework Challenge #2
46:34
Homework Challenge #2 (Cont.)
48:06
Homework Challenge #2 (Cont.)
48:07
Homework Challenge #2 (Cont.)
49:17
Homework Challenge #2 (Cont.)
49:18
Homework Challenge #3
50:08
Homework Challenge #3
50:09
Constants

19m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Constants vs. Variables
0:55
Constants vs. Variables
0:56
Constant Identifiers
2:28
Constant Identifiers Definition and Examples
2:29
Declaring Constants
3:47
Two Ways of Declaring Constants
3:48
Syntaxes
4:10
Major Difference in the Two Forms
4:48
Using Constants Example
6:25
Using Constants Example
6:26
Coding Conventions
11:08
Constant Names
11:09
define () Function
11:42
Meaningful Names
12:00
$_SERVER Superglobal
12:23
$_SERVER
12:24
$_SERVER ['DOCUMENT_ROOT']
13:15
$_SERVER Superglobal Example
13:52
Homework Challenge
17:40
Homework Challenge
17:41
Web Application Development

26m 29s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 6.0
1:13
Version 6.0 & Version 5.1 Review
1:14
Version 6.0 Changelog
11:24
Version 6.0 Changelog
11:25
Version 6.1 Changelog
12:00
Version 6.1 Changelog
12:01
Version 6.1 Coding Example
12:42
Version 6.1 Coding Example
12:43
Version 6.2 Changelog
15:18
Version 6.2 Changelog
15:19
Version 6.2 Coding Example
18:19
Version 6.2 Coding Example
18:20
Homework Challenge
25:24
Homework Challenge
25:25
Conditional Control Structures

18m 58s

Intro
0:00
Lesson Overview
0:26
Lesson Overview
0:27
Statement Groups
0:57
Statement Groups
0:58
Example
1:10
Conditional Control Structures
1:38
Conditional Control Structures
1:39
PHP Control Structures
1:56
if Statement
2:32
if Statement
2:33
if Statement (cont.)
3:49
if Statement Coding Example
3:50
else Statement
7:26
else Statement
7:27
if/else Statement Coding Example
8:50
isset() Construct
9:59
isset() Construct
10:00
isset() Construct Coding Example
12:00
Coding Conventions
15:13
Coding Conventions
15:14
Coding Conventions (Cont.)
16:39
Coding Conventions (Cont.)
16:40
Homework Challenge
17:25
Homework Challenge
17:26
Error Handling

19m 8s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Error Handling in PHP
0:41
Error Handling in PHP
0:42
Coding Example
1:45
error_reporting() Function
7:02
error_reporting() Function
7:03
Coding Example
8:04
Additional Error Directives
9:02
display_errors
9:13
log_errors
9:37
error_log
9:50
track_errors
10:12
Coding Examples
10:29
Error Control Operator
13:38
Error Control Operator & Coding Example
13:39
Homework Challenge
16:19
Homework Challenge
16:20
Homework Challenge (cont.)
17:58
Homework Challenge (cont.)
17:59
Logical & Ternary Operators

23m 22s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
Logical Operators
0:49
Logical Operators Definition
0:50
NOT (!)
1:08
OR ( ||, or)
1:35
AND (&&, and)
2:08
XOR (xor)
2:30
Logical Operators (cont.)
2:54
The OR and AND Logical Operators
2:55
Precedence of Logical Operators
3:35
Logical Operators Coding Example
3:58
Logical Operators Coding Example
3:59
Short-Circuit Operators
9:54
Short-Circuit Operators
9:55
Coding Example
10:49
Ternary Operator
14:07
Ternary Operator
14:08
Syntax and Example
14:24
Coding Conventions
17:36
Coding Conventions
17:37
Homework Challenge
19:08
Homework Challenge
19:09
Homework Challenge (cont.)
20:26
Homework Challenge (cont.)
20:27
Web Application Development

19m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 6.2 Review
0:26
Version 6.2 Review
0:27
Version 7.0 Changelog
2:39
Version 7.0 Changelog
2:40
Version 7.0 Coding Example
4:35
Version 7.0 Coding Example
4:36
Version 7.1 Changelog
12:43
Version 7.1 Changelog
12:44
Version 7.1 Coding Example
13:52
Version 7.1 Coding Example
13:53
Homework Challenge
17:42
Homework Challenge
17:43
More Conditional Control Structure

20m 49s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
elseif Statement
0:45
elseif Statement
0:46
elseif Statement Coding Example
1:22
Multiple elseif Statements
2:16
Multiple elseif Statements
2:17
Multiple elseif Statements Coding Example
3:07
Adding an else Statement
5:44
Adding an else Statement Overview
5:45
Adding an else Statement Coding Example
6:50
switch() Statement
8:07
switch() Statement
8:08
switch() Statement (Cont.)
9:14
switch() Statement (Cont.)
9:15
switch() Statement Coding Example
11:09
default Case
14:20
default Case
14:21
default Case Coding Example
15:13
Coding Conventions
15:57
Coding Conventions
15:58
Coding Conventions (cont.)
17:10
Coding Conventions (cont.)
17:11
Homework Challenge
18:06
Homework Challenge
18:07
Homework Challenge (cont.)
19:18
Homework Challenge (cont.)
19:19
Nested Conditional Control Structures

24m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Nested Control Structures
0:36
Nested Control Structures
0:37
Nested Control Structures Coding Example
2:08
Coding Conventions
6:34
Nested vs. Not Nested Control Structures
6:35
Debugging Control Structures
7:51
Debugging Control Structures
7:52
Incorrectly Specified Test Conditions and Forgetting a Break Statement
8:32
Incorrectly Placing an Opening or Closing Curly Brace
12:14
Debugging Tips
16:24
Tracing the Execution of Your Code
16:25
Adding Echo Statement
17:15
Homework Challenge
21:41
Homework Challenge
21:42
Homework Challenge (cont.)
23:08
Homework Challenge (cont.)
23:09
Web Application Development

28m 20s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 7.1 Review
0:46
Version 7.1 Review
0:47
empty () Construct
1:38
empty () Construct
1:39
empty () Construct Coding Example
2:37
Version 8.0
5:32
Version 8.0 Overview
5:33
Version 8.0 Coding Example
7:08
Version 8.0 Coding Example
7:09
Version 8.1
16:13
Version 8.1 Overview
16:14
Version 8.1 Coding Example
19:48
Version 8.1 Coding Example
19:49
Homework Challenge
26:19
Homework Challenge
26:20
Sending Email Using PHP

43m 50s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
Built-in Mail Extension
1:28
Built-in Mail Extension
1:29
SMTP Overview
2:04
SMTP Overview
2:05
SMTP - Windows
3:08
SMTP - Windows
3:09
SMTP - Linux/UNIX
4:58
SMTP - Linux/UNIX
4:59
Mail Configuration Directives
6:35
Mail Configuration Directives
6:36
Coding Example
7:48
Mail Server Authentication
10:20
Mail Server Authentication
10:21
fake sendmail Program
12:27
fake sendmail for Windows
12:28
Main 'add-on' feature
13:03
Username & Password
13:25
SMTP - XAMPP for Windows
14:07
SMTP - XAMPP for Windows
14:08
Sendmail Example
16:19
Sendmail Example
16:20
mail() Function
18:39
mail() Function
18:40
additional_headers
19:45
'From' Header
20:12
mail() Function Coding Example
21:09
mail() Function Coding Example
21:40
Web Application Development
31:43
Version 9.0 Changelog
31:44
ContactUs.php
32:52
ContactUs.php
32:53
contactInfo
33:45
Version 9.0 Coding Example
34:31
Version 9.0 Coding Example
34:32
Homework Challenge
41:32
Homework Challenge
41:33
User-Defined Functions

56m

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Defining Functions
1:29
Four Parts of Defining a Function
1:30
Functions Example 1
2:29
Function Parameters
5:29
Function Parameters
5:30
Functions Example 2
8:20
Return Statements
12:53
Return Statements
12:54
Functions Example 3
14:20
Where to Define Functions
20:34
Where to Define Functions
20:35
include_once Construct
22:10
include_once Construct
22:11
include_once Coding Example
23:55
Reasons to Use Functions
27:44
Take Advantage of Code Reuse
27:45
Improve Code Readability
29:56
Use Instead of 'content' Include Files
32:12
Web Application Development
34:42
Version 10.0 Changelog
34:43
Version 10.0 Coding Example
37:55
Version 10.0 Coding Example
37:56
Outputting HTML in Functions
47:04
Outputting HTML in Functions
47:05
Example
49:02
Coding Conventions
53:16
Coding Conventions
53:17
Homework Challenge
54:33
Homework Challenge
54:34
Variable Scope

31m 37s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is Variable Scope?
0:57
Variable Scope
0:58
Global Scope
1:15
Local Function Scope
1:50
Variable Scope Coding Example
2:26
Variable Scope Coding Example
2:27
global Keyword
8:52
global Keyword Overview
8:53
global Keyword Example
9:25
Superglobals
12:34
Superglobals
12:35
Superglobals Example
14:53
Pitfalls of Global Variables
18:34
Pitfalls of Global Variables
18:35
When to Define Variables
22:09
When to Define Variables
22:10
Putting It All Together
22:56
Putting It All Together Example
22:57
Function Scope
28:56
Function Scope
28:57
Homework Challenge
29:41
Homework Challenge
29:42
Homework Challenge (cont.)
30:59
Homework Challenge (cont.)
31:00
Web Application Development

28m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 11.0 Changelog
0:56
Version 11.0 Changelog
0:57
processGetVar()
1:42
processGetVar() Overview
1:43
processGetVar() Example
2:25
emailComments()
6:35
emailComments() Overview
6:36
emailComments() Example
7:14
outputItemLink()
11:19
outputItemLink() Overview
11:20
outputItemLink() Example
11:45
calcCartTotal()
19:25
calcCartTotal() Overview
19:26
calcCartTotal() Example
21:14
Homework Challenge
25:56
Homework Challenge
25:57
Optional Parameters

19m 35s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Optional Parameters
0:26
Optional Parameters Definition
0:27
Default Values
0:53
Optional Parameters Coding Example
3:26
More on Optional Parameters
6:55
Multiple Optional Parameters
6:56
Coding Example
8:05
Homework Challenge
16:18
Homework Challenge
16:19
Web Application Development

23m 7s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 12.0 Changelog
0:55
Version 12.0 Changelog
0:56
Update to outputLink()
1:44
Update to outputLink()
1:45
outputLink() Coding Example
2:40
outputImg()
13:57
outputImg() Overview
13:58
outputImg() Coding Example
15:35
Homework Challenge
22:05
Homework Challenge
22:06
Introduction to Conditional Loops

57m 20s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
while Loop
0:48
Definition
0:49
Syntax and Usage
1:12
Coding Example
3:33
Looping Over Arrays
13:16
Looping Over Arrays
13:17
Coding Example
13:53
Looping Over Arrays (cont.)
16:43
Internal Array Pointer
16:44
Array Traversal Functions
17:29
current ()
17:30
next () and prev ()
18:16
reset () and end ()
19:25
key ()
19:40
Indexed Arrays: Using current () and next ()
20:40
Indexed Arrays: Using current () and next ()
20:41
Associative Arrays: Using key (), current (), and next ()
24:06
Associative Arrays: Using key (), current (), and next ()
24:07
Array Traversal Functions (cont.)
29:41
list () Construct and Example
30:07
each () Construct and Example
34:40
Lopping Over Arrays Using list(), each()
42:13
Lopping Over Arrays Using list(), each()
42:14
Control Structure Scope
50:37
Definition and Example
50:38
Control Structure Scope Coding Example
51:59
Coding Conventions
54:20
Coding Conventions
54:21
Homework Challenge
54:58
Homework Challenge
54:49
More on Conditional Loops

35m 50s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
do-while Loop
0:42
do-while Loop
0:43
Simple do-while Loop Example
1:51
Another do-while Loop Example
4:09
continue Statement
10:46
continue Statement
10:47
For Example
11:07
continue Statement Coding Example
12:44
break Statement Re-Visited
18:10
break Statement Re-Visited
18:11
break Statement In while Loops Example
19:38
Infinite Loops
23:26
Infinite Loops
23:27
Coding Example
24:57
Common Loop Pitfalls
25:59
Counter Initialization Occurs in Loop
26:30
Counter Not Incremented in Loop
29:30
Unreachable Break Statement
30:50
Coding Conventions
33:48
Do-while Statements Coding Conventions
33:49
Homework Challenge
34:28
Homework Challenge
34:29
Web Application Development

22m 7s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 13.0 Changelog
0:48
Updating 'viewCart.php' and calcCartTotal()
0:49
Creating isValidCart()
9:22
Adding Three New Item to the Store & Links
15:56
Version 13.1 Changelog
17:20
Updating outputItemLink() to Remove Its Global Dependency on $itemCatalog
17:21
Homework Challenge
20:34
Homework Challenge
20:35
For & Foreach Loops

29m 28s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
for Loops
0:45
for Loops
0:46
Expression 1
1:22
Expression 2
1:47
Expression 3
2:01
Simple Example
2:27
Simple Example
2:28
Notes on for Loops
8:56
Notes on for Loops
8:57
Ending Loop Using Test Condition and Break Statement
10:06
Ending Loop Using Test Condition and Break Statement
10:07
foreach Loops
12:03
foreach Loops
12:04
Indexed Array Syntax
14:10
Syntax
14:11
Example
15:23
Associative Array Syntax
18:31
Syntax
18:32
Example
19:47
Coding Conventions
25:05
for Loops
25:06
foreach Loops
25:58
Homework Challenge
26:52
Homework Challenge
26:53
Web Application Development

25m 58s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 14.0 Changelog
1:19
Version 14.0 Changelog
1:20
Version 14.0 Coding Example
1:57
Version 14.0 Coding Example
1:59
Version 14.1 Changelog
5:39
Version 14.1 Changelog
5:40
Version 14.1 Coding Example
7:06
Version 14.1 Coding Example
7:07
Version 14.2 Changelog
15:37
Version 14.2 Changelog
15:38
Version 14.2 Coding Example
16:25
Version 14.2 Coding Example
16:26
Homework Challenge
23:35
Homework Challenge
23:36
Conditional Loop Wrap-Up

23m 12s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Nested Conditional Loops
0:39
Nested Conditional Loops
0:40
Coding Example
1:10
continue & break Re-Visited
5:17
Continue Statements and Coding Example
5:30
Break Statements and Coding Example
11:34
Loop Debugging Tips
15:16
Add Short Debug Statement At the Very Beginning
15:17
Output a Counter Variable
18:10
Add Debug Statement At the Very End
19:20
Homework Challenge
20:20
Homework Challenge
20:21
Homework Challenge (cont.)
22:00
Homework Challenge (cont.)
22:01
Variable-Length Parameter Lists

22m 16s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Variable-Length Parameter Lists
0:34
Variable-Length Parameter Lists
0:35
Coding Example
1:51
Variable-Length Parameter Lists (cont.)
5:21
When a Parameter List is Defined For the Functions
5:22
Coding Example
6:32
Variable Type Functions
9:54
is_int (), is_float (), is_string (), and is_bool()
9:55
is_ array ()
10:50
is_null ()
11:01
Variable Type Functions Coding Example 1
11:27
is_numeric() and Example
15:57
Variable Type Functions Coding Example 2
17:12
Homework Challenge
19:35
Homework Challenge
19:36
Homework Challenge (cont.)
20:52
Homework Challenge (cont.)
20:53
Web Application Development

38m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 15.0 Changelog
0:33
outputLink (), outputImg (), is_array () and is_string ()
0:34
Version 15.0 Coding Example
1:31
Version 15.0 Coding Example
1:32
Version 15.1 Changelog
7:55
Removing Redundant Code and Adding New Function Called outputHtmlTag ()
7:56
Version 15.1 Coding Example
8:37
Version 15.1 Coding Example
8:38
Version 16.0 Changelog
14:55
Creating emailOrder() Using New Constants ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT
14:56
Version 16.0 Coding Example
16:30
Version 16.0 Coding Example
16:31
Version 16.1 Changelog
32:21
Creating formatAsDollars ()
32:22
Version 16.1 Coding Example
32:57
Version 16.1 Coding Example
32:58
Homework Challenge
36:27
Homework Challenge
36:28
Miscellaneous Topics

31m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
register_globals Directive
0:58
register_globals
0:59
Coding Example
2:04
$_GET vs. $HTTP_GET_VARS
4:07
$_GET vs. $HTTP_GET_VARS
4:08
register_long_arrays Directive Coding Example
5:44
Magic Constants
7:30
Magic Constants
7:31
__LINE__, __FILE__, __FIR__, and __FUNCTION__
8:16
Coding Example
9:06
exist() & die()
13:19
exist() & die()
13:20
Coding Example
14:08
Execution Operator
16:23
Execution Operator
16:24
Coding Example
17:27
Array Operators
18:23
Equality (==) and Inequality (!=, <>)
18:43
Identity (===) and Non-Identity (!==)
19:13
Union (+) Operator
19:41
Array Operators Coding Example
20:07
Variable Variables
24:13
Variable Variables
24:14
Coding Example
26:07
Variable Functions
28:02
Variable Functions
28:03
Coding Example
29:13
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to PHP
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (17)

0 answers

Post by Jean Uwumuremyi on October 21, 2016

Excellent teacher, I tried another course here on Educator and did not like the teacher's style (so boring), I was about to cancel my subscription but this teacher made me change my mind. He should get a raise.

0 answers

Post by sorin dragon on March 16, 2016

The new zend link for coding style is:

http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html

0 answers

Post by Robert Kinnell on September 1, 2013

In lecture 8 my exercise files do not match what is displaying on the lecture video, and i downloaded them twice to make sure. For instance web-app version 1.0 is not the same. Shame on Educator.

0 answers

Post by Adil Alkarkhi on June 24, 2013

Please I need help
Include statement doesn't work with me, I put just the file doesn't work. I put the whole source still not working, I feel frustrated. Can you advice me what the problem?

0 answers

Post by Chad Buie on February 26, 2013

For SEO purpose, you should never use includes for a title tag. This will be frowned upon as duplicate title tags. Nice concept to see how to update various pages, but not for SEO tags. Ensure that you include keyword unique strings there instead.

0 answers

Post by William Herbert on July 27, 2012

How do I get the "Mock Store" loaded up into my Firefox Browser so that I can actually see it working?

Thanks

2 answers

Last reply by: Matthew M.
Wed Apr 11, 2012 4:06 PM

Post by Evan Picow on March 22, 2012

You da man Matt!

1 answer

Last reply by: Matthew M.
Wed Apr 11, 2012 3:28 PM

Post by David Lee on March 1, 2012

I am really liking your teaching style and methods. very easy to follow and understand esp for someone who doesnt have any computer science knowledge.

1 answer

Last reply by: Matthew M.
Wed Apr 11, 2012 3:35 PM

Post by Ernest Dube on February 28, 2012

the link "Download training files_lecture_8" you have provided has no materials for the"Introduction to our web application" development.why? are they going to be provided in the up coming lessons?

0 answers

Post by Dustin Sisler on February 6, 2012

On the right side above the course syllabus, you can download.

2 answers

Last reply by: Matthew M.
Tue Feb 7, 2012 3:37 AM

Post by Jacob Case on October 30, 2011

How many times do I have to attempt to load this video before I can view it? I've been sitting here for 30 minutes trying to load it and it keeps failing.

Include Files & Web Application Introduction

  • An include statement is used to include the contents of one PHP file within another PHP file. The included file is referred as an ‘include file’.
  • If a file included via an include statement cannot be found, PHP will issue a warning, and the script will continue executing.
  • A require statement performs the same action as an include statement, except that if the file to be included cannot be found, a fatal error occurs halting the execution of the script.
  • Code reuse is a practice used to place redundant or common PHP and HTML code in separate files allowing you to make changes in one place and have it affect many places.
  • For this course, include files containing only HTML will have a .html extension. Those containing only PHP code will have a .php extension, and those containing both HTML and PHP code will have a .phtml extension.
  • Each version of the store web application will be located in a intro2php/web_app/version-x.x directory in the document root. Include files for each version will be contained in a corresponding intro2php/web_app/version-x.x/includes directory.
  • Additional Resources:

Include Files & Web Application Introduction

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:16
    • Lesson Overview
  • include Statement 0:47
    • include Statement: Definition
    • Include Statement: Syntax
    • include Statement: Example
  • include Path 6:32
    • Absolute and Relative Path
    • Specified Path
    • Not Specified Path
  • Code Reuse 9:35
    • Code Reuse
    • Example
  • require Statement 12:56
    • require Statement: Definition
    • require Statement: Syntax
    • Include versus Require
  • Coding Conventions 16:33
    • Coding Conventions
  • Introduction to Our Web Application 20:32
    • Introduction to Our Web Application
    • Updating Web Application
    • Web Application Example
  • Homework Challenge 35:33
    • Homework Challenge
  • Homework Challenge (cont.) 37:38
    • Homework Challenge (cont.)

Transcription: Include Files & Web Application Introduction

Hello, and welcome back to Educator.com's Introduction to PHP course.0000

Today's lesson is a very exciting lesson, because we are going to start working0004

on our mock store Web application that we had talked about in the introductory lesson.0007

In order to do that, we are also going to learn about the topic of include statements.0012

In today's lesson, we are going to talk about, as mentioned, include statements, something known as the include path,0019

and we are going to talk about the importance of code reuse, which is an extremely important topic,0025

something known as require statements, and then, as we often do, we are going to talk about coding conventions as it relates to include and require statements.0030

And then, finally, the exciting part is: we are going to get into our introduction to our web application.0040

What is an include statement? Well, essentially, an include statement is a statement in your PHP code that allows you0049

to include the contents of one PHP file within another.0057

The included file is often referred to as the included file.0061

Now, the included file is treated as PHP code, and it gets executed accordingly.0067

Any variables that you defined in your PHP code and in your main PHP script prior to an include statement are available in the include file.0077

And any variables that you defined in the included file are also available in the rest of the main PHP script, and we will see a little more of that in a second.0084

One thing to note is that, when PHP reaches an include statement, which looks like these two statements down here,0094

it goes and fetches that file, and it starts processing it.0102

When it processes it, it enters in HTML mode, just like it does when it starts beginning to process a PHP file.0106

It assumes that everything is not PHP code, so in order for you to include PHP code in an include file,0113

you have to properly delimit the code with the PHP opening and closing tags.0120

Now, in PHP, there are two syntaxes for the include statement.0126

The first one here doesn't make use of parentheses, and the second one here makes use of parentheses.0131

They both function the same exact way; in this course, we are going to be using the one without the parentheses.0140

Let's take a look at what we might use an include file for.0148

We have a page here called includeExample.html, and it's a simple HTML page with a content section.0151

What we can do is sort of subdivide this into a header section, a footer section, and a content section.0162

What we can do is take the beginning information, or the header section of the web page, and separate it out into a separate file.0171

In this case, it is called header.html;0181

what we have done is: we have taken the beginning of this file out, and we are going to place it in a separate file here.0184

Then, what we are also going to do is take out the footer section, the end section, of the web page,0191

and we are going to include it in a file called footer.html.0196

Now, what that is going to allow us to do is: if we rename includeExample.html to includeExample.php and make use of include statements,0200

we can get the same web page.0210

What we have done here is: we have a PHP file, and it starts off with the line include 'header.html'.0212

What that is going to do is: when it reaches this line of code, it is going to go out and find header.html and process this content,0219

just as if it were already in its file to begin with.0232

Then, after it finishes the inclusion, it is going to go ahead and continue processing this as just straight HTML, which it passes on to output.0234

And then, it is going to reach another PHP tag section with another include file.0244

And what that is going to do is go and include the footer.html file, which simply contains HTML.0249

So, PHP is going to process this file, and since it's just HTML, it is simply going to output it.0254

By the time we get to the end of the file, we have the same file as here before, except it's sort of spread out in different parts over three different files.0261

And what that allows us to do (which you will see): it allows us to create a template, in that we can simply...0272

for each page, we have it look like this, with this sort of template; and every page can have the same header and the same footer,0281

and all that differentiates one page from the next is the actual content.0288

What that means is that we can go ahead and change something in, let's say, the header file--for example, maybe we have a logo at the top of the page.0295

We can change that in just the one include file, and it is going to update all of the pages.0302

If we actually go and take a look at...this is lecture 8...includeExample.html, this is what the file looks like.0308

It has a simple Content Goes Here header.0318

And if we blow this up, this is what the source code looks like.0322

Now, if we go back and we look at includeExample.php, which is the one with the include statements,0328

what we should find is that it prints out the same HTML; and if we actually go and look at the source code, the source is the same, as well.0339

Here you can see...the only difference is that, in this one, I have changed the title to .php, because it's a different file name.0351

But basically, what has happened is: in this file, PHP has inserted the contents of header.html at the beginning.0359

It inserted the content that was in the main file, which was includeTest.php, and then it outputted the footer information contained in footer.html.0369

As you see, it has the desired effect of creating the same web page.0385

You may have noticed that, in the include statement, it is the include--0396

the statement begins with the word include, and then a file name specified in between quotes.0402

And what that does is: that tells PHP which file to include.0410

One thing to note is that the file name specified can also have an absolute or relative path preceding the file name.0416

What that does is: that tells PHP exactly where the file is located on your computer, or on your web server, so that it will know where to find the file.0428

Now, if the path is specified, PHP is going to go and look at the exact location you specify, whether it's through an absolute path or a relative path.0436

And if it can't find the file, it is going to issue a warning at that include statement; but then it is going to continue processing the rest of the file.0446

The other alternative is if a path is not specified...which...if we look at our example, we didn't specify a path; we just have the file name.0455

Because it resides in the same directory, we actually could have done ./, which means the current directory, and that would have been a relative path.0465

If a path is not specified, PHP searches for the file in locations specified by the include_path directive in php.ini.0478

We talked a little bit about the php.ini file in a previous lesson; basically, that is the main configuration file for PHP.0488

There is a directive in there called include_path, and it lists all of the directories,0496

when you use an include statement, that PHP should search--that Search should search to find the files it is looking for.0501

If it can't find the file in those directories specified by include_path, then it finally looks in the running script's current directory,0508

which is what happened in our case, and loads the file.0517

Now, if it can't find the file in any of those locations, it does the same thing as if a path were specified.0521

It is going to issue a warning that the file couldn't be found, and then it is going to continue to process the script.0527

So, as you can see here, we have just used the file name for our include; we used header.html.0536

What happened was: when PHP went to process this, because no path was specified, it went out;0550

it went to the include_path directive; it searched all of the directories in there for this file; and if it couldn't find it in there,0556

it looked in the current directory, which is where it was; it was hiding in the same directory as includeExample.php.0565

Code reuse--one of the great things about using include files is: it facilitates a programming concept known as code reuse, which is extremely important.0577

What that allows you to do is: it allows you to place redundant and/or common HTML or PHP code in separate include files,0588

and then include them in as many pages as needed.0598

What that does is: that allows you to put the same content that is in maybe five different pages all in one file.0601

So, in order to update all of the different pages, you only update one file.0607

Now, that is great, because it increases your efficiency, because instead of...0611

Let's say you wanted to change maybe a link in the header section of a web page.0615

Instead of having to go up and manually update the HTML for maybe five different files, you simply update it in the include file.0620

And if the include file is included in all those pages, they automatically receive the update,0627

so it reduces the amount of time it takes to update your website.0633

The other advantage it has is that it is going to reduce the number of opportunities for errors to occur,0636

because, let's say, you have to go and update the link in five different files; that gives you five opportunities to maybe misspell...0642

maybe it's a really long link, so you might have five opportunities to misspell the link.0648

In our case, or in the case of using an include file, you only have to update it in one spot, so there is one chance for a mistake.0653

And also, if you do make a mistake, you only have to update it in that one file to change it.0659

Let's look at an example of how we can make use of code reuse to our advantage.0665

What we can do is: we have header.html, and this is the header.html file we were just using;0673

and let's say we want to include a style sheet to all the pages.0682

Let's say this was the header file for five different pages.0686

We have a style sheet that I have created called includeExample.css, which has one simple CSS directive in it.0691

And so, what we can do is go back to our include file...first, let's take a look again at what the page looks like; refresh it; it says Content Goes Here.0698

When we apply the CSS to it, it should turn red.0710

If we go ahead and include the CSS file, and we save it, now when we go to view the page again, we can see that it turns red.0714

And if you look at the page source, we can see that that link tag was added to the header of our page.0745

Now, this would be great if, let's say, we had a hundred different pages in our website,0752

and we wanted to add a style sheet to be used for all of them.0757

We simply would (let's blow this up a little bit, so you can see it) add this one line to our include file, and it's going to go ahead and update all of our pages.0760

That is the benefit of code reuse.0770

Now, there is an analog to the include statement known as the require statement.0777

Require statements work exactly as the include statement does.0781

It takes the contents of the file that's specified and includes it and processes it in the current script.0784

The only difference is that, if it cannot find the file, a fatal error occurs that halts the execution of the script0791

wherever the require statement that caused the error happened.0801

And so, that is different from the include statement in that the include statement will issue a warning, but it will continue processing the script.0805

Require statements have two forms as well, and they both look the same as the include statement.0813

One is with parentheses; one is without; and it's the same format you use to require...the require statement,0819

and then, you simply include the file name that you want to have included.0826

There is a lot of debate in the PHP community as to when to use the require statement versus an include statement.0833

Some say that any file that is absolutely necessary for your web application to run--0839

you should use a require statement, because your application should fail if it doesn't have the necessary parts.0844

On the other hand, with an include statement, because it doesn't have a fatal error that halts the execution of the script,0851

there are ways in PHP that we'll learn about later where you can handle the errors, so you can do a more graceful exit,0860

instead of just having a fatal error message appear on your screen.0864

That is actually the convention that I prefer to use--the include statement rather than the require--0868

because it allows you, if an error does occur, if you can't find the include file,0874

to put out a message that says "We are having trouble with the website right now," as opposed to a very terse PHP message.0880

Let's go back and take a look at our file.0888

Let's say, for example, in includeExample.php, we misspell the name of the header file to include.0893

So, if we go and reload this file, we can see that we get a warning.0900

It is basically saying that it couldn't find the file we tried to include, which was called header1.html.0908

But as you can see, it went ahead and it processed the content and continued to process the script and output the content in the footer.0915

So, if we look at the source, we can see that this up here...these first couple of lines are HTML generated by PHP, describing the error.0921

But then, you can see that the content section was output, as well as everything that was in footer.html.0934

Now, on the other hand, if we were to go back to this file and we were to use a require statement instead0940

(and again, we are going to have header1.html as the file, which is an incorrect file--it's not the real file name--so it's going to cause an error),0951

and we go back and browse the page now, all we get is a fatal error.0958

If you notice, the rest of the file does not get processed; the content does not show, and the footer does not show.0963

So, all we have in our source is the PHP error message.0969

And so, what that does is: it doesn't allow you to be able to handle the error and maybe output something that looks a little nicer0976

than this very terse error that would be confusing to the user.0985

As always, we talk about coding conventions as they relate to the different things we learn about in a particular lesson.0995

In this course, we are going to have different kinds of include files.1002

We are going to have files that might only include HTML, files that are just PHP code, and files that contain a mixture of both.1005

The convention we are going to use in this course is: any include file that just has HTML is going to have an HTML extension.1014

And, as you can see in our include files, they were all HTML, and so we had the .html extension.1023

If a file contains only PHP code, it is going to have a .php extension.1031

And if it contains a mixture of HTML and PHP, it is going to have a .phtml extension.1040

And basically, this is just a convention that makes it easier to understand, when you see an include file, what is actually contained in the include file.1045

For example, if it has a .php or a .phtml extension on it, we know that there is executable PHP code in there.1054

So, if we are getting an error in our application, we can know to look in those files to possibly find out the source of an error,1063

whereas, if it's just an include file with .html, assuming we follow the convention of only including HTML in our .html include files,1069

we know that we don't have to look there for PHP errors.1078

The other thing that we use in this course is: we always use the non-parentheses version of both the include and require statements.1083

Taking a look at how you can use the .phtml and .php extensions for include files...I created a file called header.php,1090

which outputs the same HTML as included in the original header.html, except it does so using echo statements.1103

If we go back to our includeExample.php file, and instead of having header.html, we put header.php (I'll change this back to include),1117

PHP is going to include this new header.php file, instead of the HTML file.1134

If we go back to our browser, and we browse includeExample.php, we can see, we get the content as expected.1140

And if we view the page source, we can see that it has both the header information that is in the new header.php,1147

the content in our main page, and then the content of the footer.html file.1154

Actually, let me blow that up a little bit for you.1159

This is the header.php output.1161

The other option is: we can use a .phtml file; I have created a header.phtml file to replace, again, header.html.1168

In this case, it is a combination of HTML code with some PHP code intermixed.1179

This is not a particularly useful example, but it's just to illustrate the point of having PHP intermingled with HTML in an include file.1185

It's just a simple echo statement that echoes the name of the file to include in the title tag.1193

If we go back to includeExample.php, change this to .phtml, and run the page (reload the page), you should get the same thing.1199

It turns out, we do; and if we go and look at the page source, everything is as expected,1210

with the header information now being drawn from header.phtml file, as opposed to header.html file.1216

Now, we are going to talk about what I think is the most exciting part of this lesson and the course--1233

the web application we introduced in our very first lesson.1239

It's a mock store web application, and today, we are going to start building up that web application.1243

We are going to make use of the include statement that we learned about today.1248

Basically, our web application that we are going to be building up--we are going to store it in the directory intro2php/web_app.1254

We are going to store it in that directory, which is under the document root.1265

This is different from storing it in lecture_8, for example, as we have been doing for the other code examples; we are going to keep it separate.1268

The other thing that we are going to do is: every time we update the web app, we are going to add1275

a new directory called version-x.x into this folder right here,1279

where x.x represents a new version number--a major and minor version number--something like 1.0, 2.0, 2.1.1287

When we do that, we are going to copy the entire contents of the whole previous version1297

into the new versions folder, and then update the files accordingly.1302

So, anything like images, CSS files--anything that would be common to all the different versions--we are still going to copy them over.1307

And the reason for that is: it makes it easier, as far as the directory structure.1316

We could actually have a common, for example, Images folder, and reference that in each of the different versions.1321

But for the sake of keeping things simple, we are going to re-copy everything each time we create a new version.1327

In version 1.0 for our app, it is just a simple HTML website; and we are going to show you that in a minute.1334

And then, what we are going to do is: we are going to use include statements to make the website template-based,1341

to take advantage of having HTML that is common to multiple pages on the website and placing it in one include file,1347

so when we make changes, we only have to make changes in one spot; and that is going to be version 2.0.1356

The other thing we are going to do is: in version 2.1, we are going to create a variable in each PHP page1363

that is going to allow us to add a custom title tag to each page.1373

Let's take a look at that.1379

I just want to open up the files for version 1.0; so let me close all these.1386

Before we get into the code for that, let's take a look at what it looks like.1401

We have a web app directory that we have created in the intro2php directory.1406

We go to version 1.0; and the main page for our web app is going to be called store.html, or eventually, store.php.1412

The reason it is not called index.php or index.html, which is the common case for the default file in the directory,1421

is because then we wouldn't get to see this directory listing right here, because Apache is configured by default in XAMPP1428

to automatically show index.html or index.php.1436

And because, for the purposes of teaching, we want to be able to individually access the different files--we want to be able to see this directory structure--1441

I have created the main file to be called something other than index.html--in this case, store.html.1448

We click on this; this is what our basic store looks like at first: Welcome to the Store Web Application!1455

And basically, it has a header section where, eventually, we will put a logo and some other things.1463

It has a content section, and it has a footer, which we commonly see in most websites, with a copyright statement and a link to the home page.1469

The store, in this case, sells a couple of different items; and right here, you can click on the different items that are available.1481

You will be able to see information about the item: you have the name, the item number, the price, an image about it, and a description.1488

And right now, in this basic version, we have just three products.1496

Now, if we go and look at the code for this, this whole website was just coded in pure HTML--just flat HTML.1505

So, every page--there is no PHP in any of the pages; they all have .html extensions.1516

All the links to the different pages are .html links, and this is what the entirety of the web pages look like.1522

Unfortunately, you can't see the whole page at once on this screen;1533

but when you are able to download the source code for this, you will be able to browse through the main file.1537

And what you will be able to see is that this is the store home page, and then each item, or each product in the store--1541

we have created a page called item- and then the item number; so for example, this one is called item-1001.html.1548

For each item, we have created their own HTML page.1558

What you can notice by looking at the website is that, when we go to the different item pages and the homepage,1565

a lot of what you see, is the same: the header is the same on all the pages; the footer is the same on all the pages.1575

So, we can make use of include files to help us out with that.1580

Now, we are going to look at version 2, which is going to use include files.1587

Let's load up the pages in our browser...and the PSPAD...and browse back to version 2.0.1597

And now, we can see that, in this case, because we are going to be using include files, each of the pages are going to be PHP pages.1613

And as you can see, we have a PHP page created for each item: item-1001, 2001, and 3001; and the main page is called store.php.1621

This website is going to look exactly the same as it did before; however, we are going to make use of include files.1633

What we can do is: if we go back and look at the new store.php page, we can see, at the very beginning here, we have an include statement.1642

And that is going to include a file called header.html, which basically is...1651

everything before the content section of the web page has been extracted into header.html.1657

And also, by the way, this is a relative link, and so we are storing all of our include files in a file called includes, and so, this is how we reference that.1665

Basically, it says that from the current directory, we go into the include folder and load header.html.1677

Now, if we look at header.html, this is simply the HTML that is common to the beginning of all of the pages in our website, placed in one file.1683

And as you can see, it ends where the content begins.1693

Likewise, you can see, at the bottom, we have an include statement that says include footer.html.1697

If we go and look at footer.html, it basically starts with the content...1705

it outputs all of the HTML from where the content ends, all the way to the closing HTML tag.1708

You can't see all of it on the screen at the same time,1716

but everything in between the first include statement and the footer include statement is the content of the page.1718

So, this is actually the content of our store homepage.1724

Now, we have done the same thing for each of the different items.1729

For example, item-1001.php--we include the same header file; we include the same footer file.1732

And then, we just have the HTML that outputs information about the product that we are going to be using--the product that the page is showing.1740

And we have that for each of the three different pages.1754

This is how we make use if include files so that, if we wanted to make one change to header.html, it would show up on all the different pages.1764

For example, right now we have this placeholder for store name--just a generic placeholder.1773

What we can do is: we can update the header.html file with the name of our store--we can give it some name of our choosing,1779

and it is going to update all of the different pages on our website.1786

That is an example of code reuse; so let's go to header.html, and this section--there is a table layout.1790

This website uses a table layout, and in the table with the ID header is where we have the store's name.1800

We are going to replace the placeholder "Store Name" with the name of the store; so for example, we are going to call it Educator.com store.1808

Then, we save it and go back and look at our web application and reload the page.1817

Now, we have updated the name of the store, and it is going to update the name on every single page.1823

So, as you can see, when we go to all the different pages, they all now have a newly-updated title.1831

Now, one thing that you may have noticed is that, in the header.html include file, in the title tag, it has Store WebApp as the title.1840

So, every page in our website right now that we go to--you can see up here--is titled Store WebApp.1850

In the beginning...at the tab at the top of your browser that shows the name of the page--right now, that outputs1857

what is in the title tag; they all say the same thing right now, which is OK for the first homepage--it makes sense--Store WebApp.1863

But for each additional page, we might want to have something where the name of the page is, for example, the name of the item.1869

Right now, because they all use the same header.html file, they all are going to have Store WebApp output as their title in the browser.1876

So, we are going to move on to the next version, where we are going to change that functionality (I'll close all these).1887

I'm going to load up the files from version 2.1, and let's take a look at what 2.1 is going to look like.1902

We go to version 2.1 and click on store.php; now, this name hasn't been changed, because we haven't updated it in this new version,1918

but we could update that, just as we have before.1927

And you can see, for the homepage, it says Store WebApp as the title of the page.1931

And now, for each of the individual product pages, it actually lists the product name as the title in your web browser.1937

And you may or may not be able to see that; but if you run the example at home, you will be able to see,1948

in the tab or at the top of your web browser, that each page has its own name that it has been given as a title.1952

We have the LCD Television title and the Baseball Bat title.1960

Now, how do we accomplish that? Well, let's look at, for example, item-1.php, which is the 100% cotton T-shirt.1966

What we can do is: at the beginning of the PHP file, before we include the header, we can define a variable called title,1978

which is what we will want to set as the title of the web page in the title tag.1990

Now, because the title tag is contained in our include file, we are going to have to have code within the include file1995

that is going to be able to take this variable, extract the title from it, and output it.2004

So, what that means is that our include file is going to have to change to a file that contains PHP code and HTML.2009

So, we are going to create a new header file called header.phtml, which means that it contains both PHP and HTML.2017

And, if we take a look at that, it turns out that the entire file is the same, except,2024

in the title tag, instead of having the name Store WebApp hard-coded into the title, we have a PHP echo statement2029

that simply echoes the output of the variable title, which we had set in the beginning of our script.2037

Now, one thing that is important here is that title has to be defined or declared before the include statement.2047

If we had defined it down here on this line instead, it is not going to work, because the include file won't know about it yet.2055

Because PHP processes things from the top to the bottom, when it reaches the include statement,2062

it only knows of variables that were declared previously in the file.2068

So, if we instead had moved it down here, the include file is not going to know about it.2072

And if we go back and look at our PHP page for the T-shirt, you will see that what it does is outputs an error as the title of the web page,2080

because PHP doesn't know about that variable; it says it's an undefined variable.2091

That is one thing that is very important: where you define the variable in your file.2096

And so, by using that, creating a title variable, before we go to the includeHeader.phtml statement,2105

we can create a custom title for each of our web pages.2113

If we look at item-2001, we can see, we have a 42'' LCD Television as the title; for item-3001, we use Baseball Bat.2115

And so, what that does is allows us to have, again, a custom title.2126

That ends what we are going to do with the web application today.2137

It is a first start, and we went from a basic plain HTML website to a template-based website, where we learned how to use code reuse,2141

and also were able to interact with some variables within the include files.2152

Now, I want to talk about the homework challenge for this lesson.2157

Basically, I am going to have you mimic some of the things that we did in the lesson today.2161

I'm going to have you create a web page containing both a header, a footer, and a content section.2167

Now, the header could be anything that you want--it could be a logo,2174

or it could be something at the top of the page that is the name of, let's say, your store that you are defining.2177

The footer can contain something like a copyright notice.2183

Create the file in the lecture_8 folder of intro2php.2186

And then, what I want you to do is do what we did here,2193

which is extract out the parts of the file that would be common to multiple web pages on that website.2195

So, the header--for example, the name of the store--would be common to all of the web pages.2202

You are going to extract that out to a file called header.html; you are going to extract out the footer content to footer.html.2206

And then, create a new PHP version of your web page that uses the include statements for the header.html and footer.html,2214

and has the content included in the middle.2223

And when you view the new PHP page in your web browser, you should be able to verify, if everything is done correctly,2226

that the HTML source code of the PHP generated by the PHP page is the same as that of your original .html web page.2234

Then, go ahead and create two other PHP web pages using the same format of2245

an include for the header, some content, and an include statement for the footer.2250

And then, what I want you to do is go ahead to the header file, header.html, and make a change--in this case, add a logo of some kind.2256

Using an image tag, you can add a logo; and when you make the change to header.html and you go ahead and view all of the other pages,2267

you should see that the logo updates on all of the different pages.2274

That demonstrates the importance of the code we use being in include files.2278

We are using the same code in multiple places, so we only have to update it in one spot.2284

Then, you should get a little experience with the differences between require and include.2289

I'm going to have you make the mistake of renaming the header file in one of your include statements,2294

so you can see the warning it generates, and you can see how it continues processing the file.2302

And then, we are going to have you change that include statement to a require statement2305

to see how that causes a fatal error that halts the execution of the script.2309

And you can see the difference between the two, and that is a way to sort of see them in action.2313

That ends today's lecture; thank you for watching Educator.com, and I look forward to seeing you next time.2318

Educator®

Please sign in for full access to this lesson.

Sign-InORCreate Account

Enter your Sign-on user name and password.

Forgot password?

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for Educator.com

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.

Use this form or mail us to .

For support articles click here.