Matthew M.

Matthew M.

Destroying Sessions

Slide Duration:

Table of Contents

Section 1: Advanced PHP with MySQL
Course Introduction

13m 36s

Intro
0:00
Advanced PHP w/ MySQL
0:13
Course Introduction
0:14
Course Content
0:59
Web Application: Educator Store
1:45
Web Application: Educator Store
1:46
Object-Oriented Programming
6:09
Object-Oriented Programming Overview
6:10
MySQL
6:50
MySQL Overview
6:51
Example: Command Prompt & MySQL
8:34
What You Will Learn
9:34
What You Will Learn
9:35
Course Prerequisites
11:52
Course Prerequisites
11:53
Advanced Course Development Environment

18m 46s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Development Environment Setup
1:36
Firefox Web Browser, XAMPP, and PSPad Text Editor
1:37
Course Directory Structure
4:36
Course Directory Structure
4:37
phpDocumentor
7:23
phpDocumentor Overview
7:24
Parsing Source Code
7:44
docs Subdirectory
9:06
Asvanced PHP Course Documentation Example
10:21
Previous Educator PHP Students
14:14
Lib Directory Changes
14:38
Images Directory Changes
14:57
VERSION Constant
15:40
Comments Noting a Specific Version Number
17:04
Homework Challenge
17:30
Homework Challenge
17:31
Introduction to File I/O

35m 37s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
File I/O
1:34
File I/O Overview
1:35
Performing file I/O: 3 Steps
1:52
File Permissions
2:28
Read Permission & Write Permission
2:29
fopen()
4:47
fopen()
4:48
Two Required Parameters
5:01
Successful fopen(): File Handle and Resource
5:21
FALSE and E_WARNING Error
6:00
Example
6:39
File Paths
7:10
File Paths
7:11
File Access Modes
9:18
File Access Modes
9:19
Coding Example: fopen()
10:31
Using Relative and Absolute Path & Non-Existent File
10:32
File Pointers
15:55
File Pointers
15:56
Example File
16:11
Opening a File with fopen() Using 'r' as the Access Mode
16:22
fgets()
17:55
fgets() Overview
17:56
Coding Example: fgets() - Reading a Line at a Time
18:26
feof()
20:10
feof() Overview
20:09
Coding Example: feof()
20:50
fclose()
23:43
fclose() Overview
23:44
Coding Example: fclose()
25:02
Coding Example: Current Stock
26:10
Coding Example: Current Stock
26:11
trim ()
31:39
trim () Overview and Example
31:40
Homework Challenge
33:35
Homework Challenge
33:36
Web Application Development

36m 36s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Version 1.0 Changelog
0:31
catalog.php
0:32
Function Library: fileLIB.php
5:00
Version 1.1 Changelog
27:12
createItemDataArray() and createDeptDataArray()
27:13
outputSimpleItemLink() and outputSimpleDeptLink()
32:06
HTTP & the POST Method

34m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
HTTP Model
1:28
HTTP Model
1:29
Client-Server Model 2 Steps Process
2:00
HTTP Messages
2:23
HTTP Messages
2:24
HTTP Requests
3:09
HTTP Requests
3:10
Example: HTTP Request Header
3:17
Coding Example: HTTP Requests
4:29
HTTP Responses
7:15
HTTP Responses
7:16
Example: HTTP Response (Header & Body)
8:00
header()
11:47
header() Overview
11:48
Coding Example: header
14:02
Coding Example: header() Error
14:52
GET Method
18:55
GET Method
18:56
Coding Example: GET Method
20:13
POST Method
21:09
POST Method
21:10
Coding Example: Sample Form Using the POST Method
23:50
Accessing POST Data in PHP
26:38
Accessing POST Data in PHP
26:39
Coding Example: Accessing POST Data via $_POST
28:15
GET vs. POST
29:54
GET vs. POST
29:55
Example: Accessing POST Data via $_POST
31:20
Example: Accessing POST Data via $_POST
31:21
Homework Challenge
33:00
Homework Challenge
33:01
Web Application Development

14m 11s

Intro
0:00
Version 2.0 Changelog
0:09
Updating the Site's Current Form to Use the POST Method
0:10
Creating Admin Website
2:55
Dynamically Generated Department List
12:40
Writing to Files

17m 38s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Review of File I/O
0:40
Review of File I/O
0:41
fwrite()
1:38
fwrite()
1:39
fputs()
2:20
'r+'
2:31
Coding Example: fwrite()
2:59
fopen() Access Modes
8:41
'a' and 'a+'
8:42
'w' and 'w+'
11:34
Homework Challenge
14:47
Homework Challenge
14:48
Web Application Development

28m 14s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Updated Open File Functions
0:19
openItemsDataFile ( ), openDeptsDataFile ( ), and openLastAddedFile ( )
0:20
insertItem()
6:25
insertItem() Overview
6:26
Functions: createItemDataString ( ) and updateLastItemAdded ( )
7:07
addItemToDepartment ()
16:03
addItemToDepartment () Overview
16:04
Functions: createDeptDataString ( ) and updateDepartment ( )
17:55
HTTP POST: File Uploads

22m 51s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
POST Data Encoding
1:13
POST Data Encoding
1:14
When Data is Included in the Body of the HTTP POST Request and is of the Content Type
1:31
When Uploading Files Using HTTP POST
3:17
Uploading Files
6:22
Uploading Files
6:23
If Encoding Type is Not Set to Multipart/Formdata
9:27
$_FILES Superglobal
10:59
$_FILES Superglobal
11:00
Structure of $_FILES
12:15
Structure of $_FILES: Name, Type, tmp_name, Error, and Size
12:16
Coding Example: $_FILES Superglobal
13:34
Moving an Uploaded File
15:39
Introduction to Moving an Uploaded File
15:40
move_uploaded_file ( ): Definition and Example
16:40
Homework Challenge
21:19
Homework Challenge
21:20
Web Application Development

15m 30s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Uploading Item Image File
1:22
Uploading Item Image File
1:23
Uploading Item Image File (cont.)
2:43
Altering insertItem ( )
2:44
Helpfer Functions: getFileExtension ( ) and moveUploadedFile ( )
4:30
isValidItem ( )
13:03
Introduction to Object-Oriented Programming

32m 44s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object-Oriented Programming
0:56
Introduction to Object-Oriented Programming
0:57
Associative Arrays
5:27
Associative Arrays
5:28
Classes
7:27
Classes Overview
7:28
Defining Classes
8:24
Defining Classes
8:25
Declaring Class Properties
9:25
Coding Example: Classes
10:11
Objects
12:18
Objects Overview
12:19
Classes vs. Objects
12:49
Classes vs. Objects
12:50
Instantiating Classes
14:58
Instantiating Classes
14:59
Coding Example: Instantiate an Item Object
16:30
Object Properties
19:21
Access and Set an Object's Property
19:22
Coding Example: Set & Access the Properties of an Item Object
24:23
Homework Challenge
30:22
Homework Challenge
30:23
Web Application Development

17m 47s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 5.0 Overview
0:50
Version 5.0 Overview and Examples
0:51
Outputting Object Properties
12:38
Outputting Object Properties
12:39
Array Object Properties
14:18
Access and Set Array Value
14:19
Object Methods

39m 57s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Object Methods
0:52
Definition of Object Methods
0:53
Calling Object Methods
3:25
Calling Object Methods
3:26
Coding Example: Simple Object Methods
4:44
Object Methods and Return Values
7:02
$this Variable
10:06
$this Variable: Definition and Example
10:07
$this Variable (cont.)
15:51
$this Variable (cont.)
15:52
Getters & Setters
21:21
Getters & Setters Methods
21:22
Object Methods In Strings
25:46
Object Methods In Strings
25:47
Coding Example: Outputting Method Return Values in Strings
27:41
Using $this to Call Other Methods
28:49
Using $this to Call Other Methods
28:50
Homework Challenge
34:18
Homework Challenge: 1-3
34:19
Homework Challenge (cont.)
36:20
Homework Challenge: 4-6
36:21
Homework Challenge (cont.)
37:52
Homework Challenge: 7-10
37:53
Web Application Development

17m 30s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 6.0 Overview
0:40
Version 6.0 Changes & Examples
0:41
Item Methods
0:53
Item Class Definition: getImageFilename()
0:54
Coding Example: getImageFilename()
1:58
Department Methods
7:33
addItem(), removeItem(), and isItemInDept() Method
7:34
addItemtToDepartment() & buildDeptObject() Functions
11:46
A Default Value Needed to Be Set for $items
16:26
Object Constructors

22m 20s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object Constructors
0:32
Introduction to Object Constructors
0:33
Coding Example: Object Constructors
1:43
Defining Constructors
3:26
Defining Constructors
3:27
Coding Example: Constructors with No Arguments
4:24
Constructor Arguments
8:09
Constructor Arguments
8:10
Coding Example: Constructor Arguments
9:49
Important Notes
16:13
Important Notes
16:14
Homework Challenge
17:35
Homework Challenge: 1 - 4
17:36
Homework Challenge (cont.)
19:13
Homework Challenge: 5 - 9
19:14
Homework Challenge (cont.)
21:40
Homework Challenge: 10 and 11
21:41
Web Application Development

16m 19s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 7.0 Overview
0:39
Version 7.0 Overview
0:40
Item Constructor
2:19
Item Constructor
2:20
Department Constructor
7:47
Department Constructor
7:48
Customer Constructor
12:23
Customer Constructor
12:24
More Magic Methods

53m 37s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Magic Methods
1:12
Magic Methods
1:13
Destructors
2:45
Destructors Overview
2:46
Coding Example: Calling Destructors
4:30
Coding Example: Object Destructor
9:19
_to String ()
16:12
_to String () Overview
16:13
Coding Example: _to String () Magic Method
18:10
Access Modifiers
21:23
Introduction to Access Modifiers
21:24
Access Modifiers: Public
21:39
Access Modifiers: Private
22:18
Access Modifiers: Protected
22:41
Object Properties and Methods
23:06
Coding Example: Public Access Modifiers
26:48
Coding Example: Private Access Modifiers
28:30
_get()
31:37
_get() Overview
31:38
Coding Example: _get () Magic Method
33:30
_set ()
36:23
_set () & the Magic Method
36:24
Using Getters & Setters
44:37
Coding Example: Using Getters & Setters
44:38
Homework Challenge
50:33
Homework Challenge: 1 - 6
50:34
Homework Challenge (cont.)
51:41
Homework Challenge: 7 - 12
51:42
Web Application Development

31m 12s

Intro
0:00
Version 8.0 Review
0:12
Version 8.0 Review
0:13
private Object Properties
1:15
private Object Properties
1:16
Coding Example
2:54
_toString() Methods
6:51
_toString() Methods
6:52
Coding Example
8:09
DataFile Class
13:27
DataFile Class & I/O Operations
13:28
Using DataFile Class: Instantiate a DataFile, DataFile open () Method, and DataFile close () Method
18:09
Homework Challenge
29:35
Homework Challenge
29:36
Classes vs. Objects

37m 49s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Class vs. Object Review
0:58
Class vs. Object Review
0:59
Static Properties
2:42
Static Properties
2:43
Scope Resolution Operator (::)
5:26
Scope Resolution Operator (::) & Static Property
5:27
Coding Example: Accessing a Static Property Using the Scope Resolution Operator
7:57
Coding Example: Accessing a Static Property in a Class Definition
10:33
Coding Example: Using a Static Property as an Instance Counter
14:18
Static Methods
18:51
Static Methods Overview
18:52
Coding Example: Static Methods
21:39
Classes vs. Objects
26:28
Classes vs. Objects: Diagrams
26:29
Class Constants
30:24
Class Constants Definition
30:25
Coding Example: Using Class Constants
31:55
Homework Challenge
34:01
Homework Challenge: 1 - 5
34:02
Homework Challenge (cont.)
35:25
Homework Challenge: 6 - 10
35:26
Web Application Development

21m 7s

Intro
0:00
Version 9.0 Overview
0:12
Version 9.0 Changes & Examples
0:13
Output Class
1:08
Output Class & Static Methods
1:09
outputHtmlSelector ( ) Method
2:43
outputItemSelector ( ) Method
4:53
outputDeptSelector ( ) Method
6:42
buildObject() Methods
11:54
buildObject() Methods & Examples
11:55
Exceptions

22m 43s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
try Blocks
0:44
try Blocks Definition
0:45
catch Blocks
2:03
catch Blocks: Definition and Syntax
2:04
Coding Example: try/catch Blocks
3:48
When an Exception Object is Caught & Error Handling
5:59
Exception Class
7:02
Exception Class
7:03
Coding Example: Using try/catch to Catch an Exception Thrown from a Method
8:04
Re-Throwing Exceptions
16:39
Re-Throwing Exceptions
16:40
Coding Example: Re-throwing an Exception
17:21
Homework Challenge
20:40
Homework Challenge: 1 - 5
20:41
Homework Challenge (cont.)
22:17
Homework Challenge: 6
22:18
Web Application Development

22m

Intro
0:00
Version 10.0 Overview
0:11
Updating addItem.php, addItemToDept.php, and error.php
0:12
Updating DataFile Class: open ( ) Method & try/catch blocks
7:45
Version 10.1 Overview
13:37
Version 10.1 Changes & Examples
13:38
Updating DataFile Class: close ( ) Method & logWarning ( )
20:17
Cookies

39m 47s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is a Cookie?
1:15
Definition of Cookie
1:16
HTTP - A Stateless Protocol
2:17
HTTP - A Stateless Protocol
2:18
Purpose of Cookies
4:10
Set - Cookie Header
6:21
Introduction to Set - Cookie Header
6:22
Coding Example: Set - Cookie Header
7:38
Cookie Header
9:45
Introduction to Cookie Header
9:46
Example: Cookie Header
10:27
setcookie()
12:33
Introduction to setcookie()
12:34
Example: Using setcookie
13:54
Cookies Attributes
15:48
Cookies Attributes Overview
15:49
Common Cookies Attributes: Domain
16:24
Common Cookies Attributes: Path
17:04
Common Cookies Attributes: Expires
19:34
Coding Example: Setting Cookie Attributes
20:58
$_COOKIE Superglobal
27:03
$_COOKIE Superglobal
27:04
Coding Example: Accessing Cookies from PHP Using $_COOKIE
29:45
Security Implications
34:44
Security Implications
34:45
Homework Challenge
36:10
Homework Challenge: 1 - 4
36:11
Homework Challenge (cont.)
37:47
Homework Challenge: 5 - 7
37:48
Web Application Development

39m 11s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
instanceof Operator
1:34
instanceof Operator
1:35
Objects with Object Properties
2:53
Objects with Object Properties
2:54
Version 11.0 Overview
6:41
Version 11.0 Changes: Cart and CartItem Classes
6:42
Version 11.0 Coding Example
10:40
Version 11.1 Overview
31:03
Version 11.1 Changes & Examples
31:04
Introduction to Sessions

46m 8s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
What is a Session?
0:53
What is a Session?
0:54
Client-Side Sessions
3:51
Client-Side Sessions
3:52
Server-Side Sessions
5:04
Server-Side Sessions
5:05
Session IDs
6:26
Session IDs
6:27
The SID is Used by the Server to:
7:08
A Client Passes an SID to the Server with Each HTTP Request Via:
8:15
Sessions in PHP
12:19
Sessions in PHP
12:20
session_start()
14:40
session_start() Overview
14:41
Coding Example: Using session_start () to Continue a Session
18:03
$_SESSION Superglobal
22:06
$_SESSION Superglobal Overview
22:07
Coding Example: Setting a Session Variable via $_SESSION
25:22
Accessing Session Data
28:08
Accessing Session Data
28:09
Deleting Session Data
31:43
Deleting Session Data
31:44
Coding Example: Deleting Session Data
32:16
Configuring PHP Sessions
36:14
session.cookie_lifetime, session.cookie_domain, and session.cookie_path
36:15
Coding Example: Configuring PHP Sessions
37:28
Configuring PHP Sessions (cont.)
40:56
session.use_cookies, session.use_trans_sid, and session.use_only_cookies
40:57
Coding Example: Configuring PHP Sessions
42:25
Homework Challenge
42:55
Homework Challenge: 1 - 5
42:56
Homework Challenge (cont.)
44:10
Homework Challenge: 6 - 10
44:11
Homework Challenge (cont.)
45:27
Homework Challenge: 11 - 13
45:28
Web Application Development

11m

Intro
0:00
Version 12.0 Overview
0:12
Version 12.0 Changes Part I: Updating 'viewCart.php' & 'checkout.php'
0:13
Version 12.0 Changes Part II
5:03
Destroying Sessions

29m 59s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Destroying Sessions
1:02
Destroying Sessions
1:03
session_destroy()
2:10
session_destroy() Overview
2:11
Coding Example: Setting a Session Variable and Destroying a Session
3:18
Deleting Session Cookies
8:38
Deleting Session Cookies
8:39
Coding example: Deleting Session Cookies
9:17
Review of Steps
21:07
Review of Steps
21:08
Garbage Collection
21:50
Garbage Collection Overview
21:51
Coding Example: Garbage Collection
24:30
Homework Challenge
26:28
Homework Challenge: 1 - 4
26:29
Homework Challenge (cont.)
28:16
Homework Challenge: 5 - 9
28:17
Web Application Development

19m 14s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
_autoload()
0:46
Introduction to _autoload ()
0:47
Version 13.0 Overview
4:06
_autoload () and SessionManager Class
4:07
Updating 'viewCart.php' & 'checkout.php'
11:16
Introduction to Databases

21m 24s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Flat Files
1:09
Flat Files: Definition and Example
1:10
Problems Associated with Using Flat Files as a Database
2:15
Relational Databases
3:29
Relational Databases
3:30
Relational Database Management System (RDBMS)
3:50
Tables
7:43
Tables
7:44
Columns
9:24
Columns
9:25
What is SQL?
10:45
Introduction to Structured Query Language
10:46
Standard Data Types of SQL
12:23
Primary Keys
13:19
Primary Keys
13:20
Primary Key Examples
16:36
Primary Key Examples
16:37
Introduction to MySQL

28m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
What is MySQL?
1:33
MySQL
1:34
MySQL Monitor
5:16
MySQL Monitor Overview
5:17
XAMPP & MySQL
5:58
In the MySQL Command: hostname, username and -p
7:05
Connecting to a MySQl Server
9:52
Connecting to a MySQl Server
9:53
Using MySQl Monitor
13:48
Using MySQl Monitor
13:49
GRANT Command
15:10
GRANT SQL Command
15:11
Privileges & Objects
18:18
Username, Hostname, and Password
19:37
Specifying Objects
20:05
Creating a PHP User Account
21:41
Creating a PHP User Account Overview
21:42
Meaning of all & *.*
23:35
Example: Creating a PHP User Account
23:48
Required Homework
26:27
Required Homework: 1 - 5
26:28
Required Homework (cont.)
27:28
Required Homework: 6
27:29
Creating Databases & Tables

23m 1s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Creating a Database
1:40
Introduction to Creating a Database
1:41
Example: Creating a Database
3:33
CREATE TABLE Command
6:43
CREATE TABLE Command
6:44
Data Types
7:39
Numeric Data Types: INT, INT UNSIGNED, and DECIMAL
7:40
String Data Types: CHAR (M), VARCHAR (M), and TEXT
9:23
Colum Attributes
11:00
PRIMARY KEY Attribute
11:01
AUTO INCREMENT Attribute
11:35
Items Table
13:07
Items Table
13:08
Useful Commands
17:04
SHOW TABLES Command & DESCRIBE Utility Statement
17:05
Example: Creating an Items Table
17:58
Required Homework
20:51
Required Homework: 1 - 6
20:52
Required Homework (cont.)
21:55
Required Homework: 7 - 9
21:56
SQL Command: INSERT

27m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
INSERT Command
1:20
SQL INSERT Command
1:21
Specifying Values
3:16
Columns with Numeric Data Types
3:17
Columns with String Data Types
3:34
Columns with AUTO INCREMENT
4:07
Inserting Items
5:21
Inserting Items
5:22
Example: Inserting Items
7:03
SQL Text Files
14:04
SQL Monitor Client
14:05
MySQL Monitor & the < Operator
15:15
Example
17:35
Required Homework
22:32
Required Homework: 1 - 6
22:33
Required Homework (cont.)
24:19
Required Homework: 7 - 10
24:20
SQL Command: SELECT

24m 57s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
SELECT Command
0:42
SELECT Command: Definition and Syntax
0:43
Results of a SELECT Query
1:53
To Specify the Retrieval of All Columns from a Table
3:06
Example: SELECT Command
4:18
WHERE Clause
7:11
WHERE Clause
7:12
A SELECT Query with WHERE Clause has the Following Syntax
8:10
A Where Condition can Contain both Logical and Comparison Operators
9:44
Literal Values
13:24
Literal Values
13:25
Example: Literal Values
14:18
ORDER BY Clause
15:31
ORDER BY Clause & SELECT Query
15:32
Ascending and Descending Order
17:30
An ORDER BY Clause can Specify Multiple Columns to Order the Rows by
18:01
Example: SELECT Query with WHERE and ORDER BY Clause
20:32
Homework Challenge
21:59
Homework Challenge
22:00
Homework Challenge (cont.)
23:54
Homework Challenge
23:55
Using PHP from MySQL

32m 43s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
PHP/MySQL Architecture
0:56
PHP/MySQL Architecture
0:57
MySQLi Extension
3:05
MySQLi Extension
3:06
Steps to Using MySQL from PHP
5:53
Four Steps to Using MySQL from PHP
5:54
Step # 3
7:18
Connecting to a Database
8:12
To Connect to a MySQL Database
8:13
To Test for Connection Errors
10:20
Running an SQL Statement
11:54
Running an SQL Statement
11:55
Example
13:30
Processing the Results
15:58
For non-SELECT Queries
15:59
MySQLi Object Property: affected_rows
16:19
For INSERT Statements on Tables with an AUTO_INCREMENT Column
18:07
Closing the Connection
19:45
Closing the Connection
19:46
Coding Example
21:24
Coding Example: Using MySQL from PHP
21:25
Homework Challenge
29:00
Homework Challenge: 1 - 4
29:01
Homework Challenge (cont.)
31:10
Homework Challenge: 5 - 9
31:11
Web Application Development

30m 30s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
sprintf()
1:28
sprintf() Overview
1:29
Example
1:56
INSERT Statements with sprintf()
5:15
INSERT Statements with sprintf()
5:16
Version 14.0 Overview
10:00
Version 14.0 Changes & Examples Part 1
10:01
Version 14.0 Changes & Examples Part 2
21:58
SELECT QUERIES from PHP

24m 22s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
SELECT Queries
1:21
SELECT Queries
1:22
MySQLi_Result Class
3:17
MySQLi_Result Class: num_rows
3:18
MySQLi_Result Class: fetch_assoc ( ) and fetch_object ( )
3:59
fetch_assoc()
5:17
fetch_assoc() Overview
5:18
Coding Example: Using fetch_assoc()
9:00
stdClass Objects
12:46
stdClass Objects
12:47
fetch_object()
14:19
fetch_object() Overview
14:20
Coding Example: Using fetch_object()
16:45
Freeing Result Set Memory
18:42
Freeing Result Set Memory
18:43
Coding Example: Using free ( )
20:01
Homework Challenge
22:07
Homework Challenge: 1 - 5
22:08
Web Application Development

17m 6s

Intro
0:00
Version 15.0 Overview
0:13
Version 15.0 Changes & Examples Part 1
0:14
Version 15.0 Changes & Examples Part 2
8:43
Linking Tables

24m 32s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
A Departments Table
1:08
Departments Table
1:09
How Could We Model This in a Table: Option 1
1:26
How Could We Model This in a Table: Option 2
3:12
Database Normalization
4:37
Database Normalization
4:38
Foreign Keys
8:47
Foreign Keys
8:48
Linking Table
11:26
Linking Table
11:27
Multiple Column Primary Keys
15:30
Multiple Column Primary Keys
15:31
Example
18:51
Required Homework
22:34
Required Homework: 1 - 3
22:35
Required Homework (cont.)
24:10
Required Homework: 4
24:11
Web Application Development

24m

Intro
0:00
Version 16.0 Overview
0:11
Version 16.0 Changes
0:12
Version 16.0 Coding Examples
4:12
Version 16.0 (cont.)
18:30
Version 16.0 Changes & Examples Part 2
18:31
SQL Command: DELETE

10m 33s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
DELETE Statement
0:30
DELETE Statement & Its WHERE Clause
0:31
Delete All Rows From a Table
2:57
Using DELETE from PHP
4:04
Using DELETE from PHP Overview
4:05
Coding Example: Using DELETE from PHP
6:37
Homework Challenge
8:53
Homework Challenge: 1 - 4
8:54
Web Application Development

16m 2s

Intro
0:00
Version 17.0 Overview
0:11
Version 17.0 Changes
0:12
Version 17.0 Coding Example
2:51
Transactions
12:50
Database Transaction
12:51
Steps in Using Transactions
14:00
SQL Command: UPDATE

32m 14s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
UPDATE Statement
0:54
UPDATE Statement & Its WHERE Clause
0:55
Example: UPDATE Statement
3:32
Using UPDATE from PHP
5:21
Using UPDATE from PHP Overview
5:22
Coding Example: Using UPDATE from PHP
6:53
htmlspecialchars()
9:04
htmlspecialchars()
9:05
Encoding Special Characters
9:23
Coding Example: htmlspecialchars()
13:41
addslashes()
20:40
addslashes()
20:41
Coding Example: addslashes()
22:52
Homework Challenge
27:55
Homework Challenge: 1 - 2
27:56
Homework Challenge (cont.)
30:14
Homework Challenge: 3 - 5
30:15
Homework Challenge (cont.)
30:41
Homework Challenge: 6 - 9
30:42
Web Application Development

12m 33s

Intro
0:00
Version 18.0 Overview
0:12
Version 18.0 Changes
0:13
Version 18.0 Coding Example
1:24
SQL: Joins

42m 16s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
DATETIME Data Type
1:52
DATETIME Data Type
1:53
Modeling Orders
5:12
Modeling Orders
5:13
Customers Table
10:46
Customers Table
10:47
Example
16:18
Example: Order Table in MySQL
16:19
Joins
22:26
Joins Overview
22:27
Inner Join
23:09
Example: Joins
24:11
Join Conditions
28:14
Join Conditions
28:15
Example
28:32
Join Queries
30:00
Example: Join Conditions in MySQL
30:36
Implicit Joins
34:42
Implicit Joins
34:43
Example: Implicit Joins
35:57
Aliases
37:28
Introduction to Aliases
37:29
Example: Aliases
38:55
Required Homework
40:32
Problem 1
40:33
Problem 2
41:01
Problem 3
41:17
Web Application Development

29m 34s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Inserting Orders
0:44
Inserting Orders
0:45
Version 19.0 Overview
3:45
Version 19.0 Changes & Example Part 1
3:46
Version 19.0 Changes & Example Part 2
13:18
Version 19.1 Overview
21:10
Version 19.1 Changes
21:11
Version 19.1 Coding Example
22:18
User Authentication

26m 13s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
User Authentication
1:31
User Authentication
1:32
Authentication with Sessions
2:34
Authentication with Sessions
2:35
Four Steps in Authentication via Sessions
2:50
Using Sessions to Restrict Access
3:58
Using Sessions to Restrict Access
3:59
Coding Example: Restricted Access Area
4:47
Authentication Methods
5:54
Authentication Methods Overview
5:55
Coding Example: Authentication Methods
7:31
Logging Out
9:57
Logging Out
9:58
Coding Example: Log Out
10:47
Users Table
13:50
Users Table
13:51
Example: Creating a Users Table
15:08
Password Hashing
17:30
Password Hashing
17:31
PHP and MySQL Built-in Hash Functions: sha1 ( ) and md5 ( )
18:43
Coding Example: Password Hashing
19:27
Required Homework
24:41
Required Homework: 1 - 4
24:42
Web Application Development

14m 36s

Intro
0:00
Version 20.0 Overview
0:13
Version 20.0 Changes & Examples Part 1
0:14
Version 20.0 Changes & Examples Part 2
5:05
Version 20.0 Changes & Examples Part 3
7:29
Version 20.0 (cont.)
8:31
Version 20.0 Changes & Examples Part 4
8:32
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 Advanced PHP
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

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.
  • Learn at your own pace... anytime, anywhere!

Destroying Sessions

  • When either the client or server determines that a session is to be ended, a session is destroyed. This serves to:
    • cut the link between any previous & any future HTTP transactions
    • get rid of transient session data that is no longer needed
  • session_destroy() is used to destroy a session. It ensures that any session data stored on the server will be deleted.
  • To properly destroy a PHP session, the following steps must be taken:
    1. Call session_start() to continue the session
    2. Explicitly delete any session data stored in $_SESSION
    3. Explicitly delete the session cookie
    4. Destroy the session data on the server using session_destroy()
  • To explicitly destroy a session cookie, the functions session_name() and session_get_cookie_params() are useful.
  • After a specified amount of time, and regardless of the expiration of a session’s cookie, a session’s data file will be considered as expired, or a garbage, by PHP.
  • PHP has a garbage collector process that will periodically run to remove any session data files that have been marked as garbage. There are several configuration directives in 'php.ini' related to session garbage collection.
  • Additional Resources:

Destroying Sessions

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:12
    • Lesson Overview
  • Destroying Sessions 1:02
    • Destroying Sessions
  • session_destroy() 2:10
    • session_destroy() Overview
    • Coding Example: Setting a Session Variable and Destroying a Session
  • Deleting Session Cookies 8:38
    • Deleting Session Cookies
    • Coding example: Deleting Session Cookies
  • Review of Steps 21:07
    • Review of Steps
  • Garbage Collection 21:50
    • Garbage Collection Overview
    • Coding Example: Garbage Collection
  • Homework Challenge 26:28
    • Homework Challenge: 1 - 4
  • Homework Challenge (cont.) 28:16
    • Homework Challenge: 5 - 9

Transcription: Destroying Sessions

Hello again, and welcome back to Educator.com's Advanced PHP with MySQL course.0000

In today's lesson, we are going to be continuing our discussion of sessions, and we are going to learn about how to properly destroy a session.0005

We are going to briefly talk about what the destruction of a session implies--what it actually means.0014

We are going to go over a built-in function to PHP that is used to destroy session data, called session_destroy.0019

And then, we are going to talk about some additional steps that you need to do, in addition to calling this session_destroy method,0027

to effectively end or delete or destroy a session.0033

That is going to involve manually deleting all of the session data and manually deleting session cookies.0039

Then, we are just going to go over a review of all of the steps that are involved in successfully ending a session.0046

And then, we are going to briefly talk about the topic of garbage collection, which talks about what happens0052

if a session is not successfully ended--what happens to that session data.0057

When either a client or a server determines that a session is over (for example, if a client wants to log out,0065

or a server decides that the user hasn't had any activity in a certain amount of time),0070

it can end that session; and that is called destroying the session.0076

What destroying the session does is undoes the two things that a session does:0082

namely, it cuts the link between any previous and any future HTTP transactions (because that is part of what a session does--0088

it links multiple requests together, so that they are considered part of the session between two parties0097

over a specific period of time), and it also gets rid of any of that session data associated with that particular session,0102

because that data is transient data, and when the session ends, it is no longer needed.0111

So, destroying a session is effectively getting rid of that data.0115

In PHP, for example, what that means is getting rid of that session data file in the tmp directory on the server,0119

freeing up that disk space to be used for other sessions.0126

PHP provides the session_destroy method that is used to destroy a session.0132

What it does is ensures that any session data stored on the server will be deleted.0139

All of those session files that we had looked at in previous lessons in the tmp directory (like sess_ and then the unique session ID)--0147

session_destroy, when it is called, deletes that session file, so that data is no longer accessible.0159

One thing to note about the session_destroy method is that, in order for you to call it in a script,0166

it has to already have or know about an initialized session, which indirectly means that, in order to call session_destroy,0174

you have to call session_start on that script before you do it.0181

This is a little counterintuitive, because you think, "OK, I'm destroying the session; why do I need to start it?"0185

But that is part of the process; so, in any script where you call session_destroy, before you call that method, you also need to call session_start.0189

Let's take a look at what session_destroy actually does.0199

We have a script called setSessionVar; this is similar to what we used in our last lecture.0207

What it does is starts a session and sets a username session variable equal to jsmith.0215

And then, it outputs a link to getSessionVar.php, which is a page that allows us to access that session variable.0221

Because it accesses session variables, it needs access to the _SESSION superglobal; in order to get that, it has to call session_start.0230

So, it is going to call session_start, which is going to see the cookie that the client provided with the session ID.0237

And then, it is going to use that to load the _SESSION superglobal.0243

Here, we have done a little bit of error checking to make sure that this username session variable does exist when the user comes to this page.0247

It is just checking: if that username session variable is set, go ahead and set this username variable to the value of that session variable.0259

And if not, we are going to set it to a string that is an italicized string, nonexistent, which means that it doesn't exist.0268

Then, what we do in the body of our HTML is: we are simply outputting that particular username that is part of the session, assuming that it exists.0279

We also output a new link that says to destroy the session; it is going to go to destroySession.php.0290

What that does is call our session_destroy method; now, as mentioned, in order to call session_destroy, you have to call session_start previously.0298

So, it calls session_start and then calls session_destroy.0308

And then, the body will attempt to output this session variable username, if it is still valid.0311

And it has the same ternary operation up here that tests for the existence of that username variable,0319

and will set username equal to that value, if it has been set.0327

And the reason why I have included this here (you might wonder why I am including that in a statement that is destroying the session)0333

is to show you the incomplete nature of what session_destroy does.0340

For example, this is our temporary directory; I'm going to delete all of our current session data files that we have in there.0346

If we go ahead and make sure that any session cookies are deleted, and then if we go to example-1, and we go to setSessionVar,0353

we can see that we have been set a session cookie that starts with r4gla.0361

If we go and look at our temporary directory that stores our session data files, we can see a data file that corresponds to r4gla.0368

The script is going to set that username variable; again, if we look it, a session variable is going to set it to jsmith.0379

So, when we click on nextPage, which is going to go to getSessionVar, we can see0384

that we are able to output and access this jsmith session variable that was set.0389

Again, we can see here that we have our r4gla cookie that was sent from the client to the server,0396

so that it knows that it is continuing this r4gla session, and therefore has access to that session variable that was set as part of that session.0402

Now, if we look here, we can still see that this session file exists.0411

And when we click on destroySession, we are going to notice a couple of things.0417

First of all, we can see that the session data file no longer exists, because session_destroy does that.0422

However, we can see that we are still able to output the username session variable.0430

If we go back and look at destroySession, we can see that, even though we have called session_destroy, we still have access to this session variable.0436

And the reason for that is that, when session_destroy is called, it doesn't destroy that session data file until after the script is finished running.0446

So, because of that, the information stored in that session data file, which has been loaded into _SESSION, is still available for the rest of this script.0454

That is why we are able to access that down here, and that is one of the issues that we are going to talk about, about destroying a session.0462

You want to manually destroy any session data that you already have, so that this can't happen--0467

because, in a way, it doesn't make sense that you are destroying a session, yet down here you are able to access that session information.0471

One thing to note is: if we go ahead and refresh that page, what is going to happen is:0479

if we look back here, when we start the session, it is still going to have that session cookie.0484

It is going to try to load data for that particular session, but because that data file has been destroyed,0490

it is not going to be able to load it, and so this username session variable is not going to exist.0495

And so, we are not going to be able to output anything.0500

If we go ahead and refresh the page, we can see that it shows nonexistent.0504

It shows that it actually did delete that data file, but when that script is immediately run, those session variables are still available.0507

To counteract that imperfection of session_destroy...not necessarily an imperfection, but intuitively, you think that0519

if you call a function session_destroy, it is going to completely end a session, but that is not necessarily the case...0529

As mentioned, one thing it doesn't do is delete the session data immediately.0537

So, it is still accessible in the rest of the script.0540

What we need to do is explicitly delete any session data, so that future portions of that script will no longer have access to that data.0544

And we can do that (as we learned about deleting session variables) using the unset method.0553

If we go and take a look at example-2, it has the same exact setSessionVar script and getSessionVar script;0560

however, its destroySessionVar script is different, in that now it actually unsets this session variable.0570

So, whereas in our last example, we tested for the existence of the variable and then set the variable username0577

to that session variable if it did exist, here we are explicitly unsetting, or deleting, the session variable.0586

Then, we call session_destroy; now, because we have called this unset method, when we go down here0594

to actually try and output the session variable username again, we are going to see that we are not going to be able to do that,0599

because we have unset that variable; so we have eliminated one of the problems with session_destroy.0606

We have now made that session variable inaccessible to the rest of the script.0610

So, we have a test down here that tests to see if that username session variable exists.0614

If it doesn't, it is going to say it is destroyed; and if it does, it is going to output it.0619

And assuming that everything works, we should never reach this else statement, because we are unsetting this session variable up here.0624

If we go and look at this new example, and clear our session cookies, and go to setSessionVar,0634

it is going to start our new session: am1j67 is the beginning of that session ID.0649

If we look at our temporary directory, we have that am1j67.0654

Now, we go to Next Page; we are going to have access to that session variable username, so we are able to output it.0659

Now, when we go to destroySession, it is going to output a message "session destroyed."0664

And additionally, in our temporary directory, we no longer have that...I don't remember what the exact name of that session ID was,0668

but we no longer have that session data file anymore, because session_destroy destroyed that after the script ended.0677

But as you can see now, the "session destroyed" message gets output, because we can see down here that0684

that session variable username is no longer available.0694

Another way (if we go back and look at our slide) to delete session variables: instead of going through0700

and individually unsetting each variable, you can just set the _SESSION superglobal array equal to the empty array,0708

which is going to erase any key/value pairs that it had.0715

So, it is going to delete any session variables that you have already created in that session.0719

And in general, that is the preferred method--the main reason being that it is easier to do,0728

and you don't have to remember every single session variable that you may have set.0733

We can go and update our script: instead of calling unset on username, we can just set _SESSION equal to the empty array.0737

And then, just to confirm that this works, we go back and delete our session cookie, and we run everything again.0751

Create a new session; v1hnaq is our session file; we are able to output that session variable.0761

Now, our session is showing that it was successfully destroyed, so that effectively deleted that variable.0774

And we no longer have that session file, which was v1hnaq; if you look back, it has been deleted.0779

So, we have still been able to delete all of our session data, and we have been able to destroy the session file.0785

Now that we have done that, there is still one more part of the process that we need to do.0794

It is: we have been able to delete our session data, which is part of destroying a session;0799

but the thing we haven't done is: we haven't been able to eliminate the connection between future HTTP requests and previous ones.0804

And that is what a session does: it links multiple requests together.0810

The reason that they are still linked together is because the session_destroy method doesn't actually destroy that session cookie.0813

Every time we continue to make requests to that website, our browser, unless that cookie is expired,0821

is still going to send that session cookie back to the web server.0826

And so, as far as our web server is concerned, it is still part of the same session.0832

And it is going to link those things together; so session_destroy doesn't destroy the session in that sense, either,0836

in that it doesn't cut that link between previous and future HTTP transactions.0842

For example, we have destroyed our session (this is example-2 again), but if we were to go back and...0850

(we can see that our session's name begins with v1hn; that is the name of our session ID)0860

try to start a new session again, setSessionVar, what we can see is that no cookie was set,0872

and we have continued to pass v1hna (that cookie) to the server, saying it is still part of the same session.0880

And that is a problem, because...it looks like when it created it, it re-created the session file, but what is going to happen is:0891

that would be a problem, because...the reason it re-created it is because this setSessionVar script...0904

what it does is goes ahead and, if the session is already created, creates that session variable.0914

So, it is going to go ahead and re-create that session data file.0919

Maybe...what I was trying to get at...a better example would be: if we go and destroy the session,0923

we can see that we still have this cookie that we are being passed.0932

If we look at the tmp directory, our data file has been destroyed, and so when we refresh this page,0937

we are still passing along that same cookie, except no session data exists for that particular file.0949

In order to sever all ties between past and future HTTP transactions, we must explicitly delete that session cookie.0959

And we do that using the setCookie method: we know that we can delete cookies0969

by setting a cookie with the same name of the cookie we want to delete with an expiration date that is in the past.0972

And there are two built-in functions to PHP that can help with destroying a session cookie.0984

One is called sessionName, which is going to return the name of sessions, which as we know is also the name of session cookies.0988

And by default, that is PHPSESSID.0994

And we use that method to load the name of the cookie that we are trying to destroy,0998

because maybe in different scenarios...this is a configurable option, so it could change.1002

Maybe somebody just, instead, decided to have session name equal to just SID.1008

That is going to allow us to load the appropriate name of the cookie to destroy.1021

Then, there is a method called sessionGetCookieParams, which allows us to get parameters of a cookie,1024

such as its domain and path, because also, when we are deleting a cookie,1029

we have to know the domain and the path for that particular cookie.1033

We need to know the name of the cookie, and then domain and path, in order to successfully delete it by setting its time into the past.1037

In our new version, version 3, setSessionVar and getSessionVar are the same.1045

However, in our destroySession, it has been updated.1051

We start the session, as we know that we need to do.1056

We have deleted any session data, and now we are going to delete the session cookie.1059

So, what we do is: we load the parameters for the particular session cookie, using this sessionGetCookieParams method.1064

And then, what we do is make short variables for all of the parameters of the cookie that we are going to be deleting.1072

We load the name of the cookie, which we use the sessionName method to do.1079

We are going to set the expiration of the cookie to expire an hour in the past, so that is going to effectively delete it.1083

We load the path of the cookie to make sure that, when we call the setCookie method,1089

we are deleting the cookie and have the path matched, so that it actually deletes the cookie.1093

And then, we also are getting a domain, so that the domain of the cookie we are deleting is going to match, so we will be able to delete it.1099

Then, we simply call the setCookie function with the name of the cookie, its path, and its domain1107

that we have been able to extract by calling this sessionGetCookieParams method.1114

And then, we are also going to set the expires, which is going to set it to expire in the past.1120

When that gets called, that Set-Cookie header is going to get sent.1125

The cookie is going to be destroyed; then we are also going to call session_destroy,1129

which is going to delete the data on the server after the script has ended.1133

And again, if we try to output the username session variable, we are not going to be able to do that, because it has been unset1138

Up here, when we deleted all the session data by setting _SESSION equal to the empty array.1145

So now, if we go and look at our new version, example-3, and delete any session cookies,1150

if we call setSessionVar, it has been assigned the ID in Set-Cookie 58k7.1161

So, remember that--that is the start of our session ID.1169

And we go to getSessionVar, where we are able to output the username method.1172

And just to refresh my memory, 58k7 is the beginning of the name of our session ID.1178

We look in our tmp directory; we can see that we have a 58k7 data file.1185

Now, when we click on...1191

Also, one other thing to note is that, if we look at our cookies currently, we have a 58k7 session cookie; so note that.1194

Now, when we click on destroySession, it is going to do those three things.1206

It is going to delete all our session data, so that we are not able to output that username variable.1211

It is going to delete the session cookie, and if we look at our HTTP header, we can see that it deleted the cookie.1216

It set PHPSESSID equal to deleted, and it set the cookie to expire in the past.1226

We have deleted the session cookie, and then, if we look at our tmp directory, we have also deleted that session data file.1231

It was 58k7, and if we look back, that file no longer exists.1237

So now, we have essentially, effectively ended our session.1243

We have deleted all the session data, so it is not available in the rest of the script.1246

We have deleted the session cookie, so that any future HTTP requests aren't linked to the session that we have just ended.1250

And then, we have also gone ahead and deleted any session data on the server associated with that session,1256

so that those server resources are available for future sessions.1261

And this is just a review of the steps that you need to properly destroy a session.1268

First, you need to call session_start, because first of all, you need to call that before you can call session_destroy.1273

And it is also going to give you access to the _SESSION superglobal, which is going to allow you to perform step 2,1279

which is to explicitly delete any session data stored in _SESSION.1284

And the easiest way to do that is just to set it to the empty array.1288

We have explicitly deleted the session cookie by calling the setCookie function and setting the session cookie to expire in the past, which will effectively delete it.1292

And then, we have destroyed the session data on the server by calling the session_destroy method.1305

Let's say that our session is not properly ended.1313

Let's say we did part of it--we have unset all of our session variables, and we have deleted our session cookie; but we forget to call session_destroy.1316

Well, what that is going to do is: that means that that is going to leave our particular session data file on the server.1325

And what happens is: in PHP, regardless of the expiration of a particular session's cookie,1333

that session's data file has a particular lifetime associated with it.1340

And it is something that you configure with the session.gc_max_lifetime configuration directive,1344

which is the number of seconds until a session data file is seen as garbage.1351

Even if you have a cookie that a user is passing back and forth to the server, that has a PHP session ID1356

for a session that it was a part of, if this max lifetime has been reached for a particular session data file,1364

then PHP may go ahead and delete that file, and so you don't have access to it.1376

It is another way of managing sessions, in which part of the reason for that is to make sure1381

that your temporary directive doesn't get filled up with all these sessions that were never effectively ended by calling session_destroy.1386

After this set amount of time, PHP considers a session data file to be garbage.1395

And PHP has what is known as a garbage collector process (and that is a term used in programming) to free up memory.1402

And what it does is: it periodically runs, and will remove any session data files that have been marked as garbage.1409

And so, what that does is allows any session data files for sessions that have gone on for too long,1415

and may not have been effectively destroyed, to keep from using up all of your server resources.1426

There are two other configuration directives: session.gc_probability and session.gc_divisor.1432

And they are advanced configuration directives (and in fact, all of these are) that we are not really going to get into the details of.1439

But basically, they describe how long it takes until a file gets marked as garbage.1446

And then also, these two describe what are the chances that that file is going to get deleted at the end of its lifetime.1451

It may continue to last for a little longer than its lifetime, depending on how these are set.1459

But they are all in the name of deleting any session data files that have gone on for sessions that no longer exist.1464

For example, if we go back to our destroySession script in our last example,1473

let's say we delete our session cookie, but we leave out the session_destroy method.1482

If we go back and re-run this example (let's delete any session cookies), and we set the session variable, and we view it;1490

we can see that we have created a session that starts with session ID nouha.1503

If we go and look at our tmp directory, we can see a session data file nouha.1509

Now, when we call destroySession, we can see that our cookie has been deleted by looking at the setCookie method.1515

So, our session cookie no longer exists, so our HTTP requests are no longer linked together.1523

However, if we look back at our tmp directory, we can see that this nouha session data file still exists,1530

because we didn't call session_destroy, and that is the purpose of session_destroy.1536

What that means is that eventually, there are default settings in php.ini that are going to know when that file is considered garbage.1540

And I think the default is about 24 minutes, or something like that.1549

And what it is going to do is check in 24 minutes; and if that file still exists, it will go ahead and delete it.1553

And that eliminates the problem where all your server memory or hard disk space1557

would get used up by sessions that were never properly destroyed.1564

Even if you do delete that cookie, if you don't call session_destroy, that data file isn't going to be deleted.1569

And so, that just talks about how the session data files also have a limited lifetime, as well.1574

In general, though, it shouldn't be something you should worry about, if you always call session_destroy when appropriate when destroying a session.1582

For the homework challenge, I want you to extend the homework challenge solution you made for lesson 25.1589

We are going to be adding a logout script to our application that is going to destroy a user's session.1595

We are going to say, "OK, when you have logged out, your session is over."1604

For example, if you were at a website where you go and log in, it might say your name at the top of each page.1607

And then, when you log out, it no longer does; that is effectively ending your session.1611

We are going to mimic that in our application by creating a script called logout.php.1616

We are going to add a link to logout.php on the members-only page, so that when we are viewing the members-only page,1621

we can click on that, and it will allow us to log out.1626

And in logout.php, at the top of the script, I want you to perform the four steps that are needed to properly destroy a session,1629

which are, again: Call session start. Delete all the session variables.1638

Delete the session cookie. And then, call session_destroy.1642

Then, if the session is successfully destroyed (which it should be, assuming that all these methods have been followed),1645

output a message that the user has been successfully logged out.1651

And then, provide him or her a link back to login.html.1655

If it wasn't successfully logged out, output an error message.1660

And again, assuming that this was done right, you shouldn't have to output that error message.1663

The way that you can test that a user is logged out is by verifying that the username session variable1668

that the user set on login.html is no longer set.1674

And again, that is how we checked to see if a user was logged in before: by just testing if the username session variable was set.1680

And so, you want to employ that test again.1692

And what you can do is: I want you to test your completed solution by logging into the site,1697

going to the members-only page, and then clicking on the Log Out link.1702

When you are on that logout page, one thing I want you to note is: note the SID of your session cookie.1707

By using Firebug, you can look at the cookie header and see what your session ID is.1713

And then, click on the link back to login.html.1717

And when you go back to login.html, I want you to log back in to the site and verify that you see1720

that a new session cookie with a different SID has been set.1726

And you will see a Set-Cookie header in Firebug; and what that is going to show you is that1730

you have successfully destroyed your session, and that you have just deleted your session cookie,1734

so that now, when you log in again and that session_start method is called, a new cookie is generated.1738

Also, verify that the session data file associated with your old SID that you looked at on logout.php has been erased.1744

And then, you also see that a new session data file, matching your new session ID, has been created.1752

One note as far as testing goes: one thing that is helpful in testing is to make sure that you delete any localhost cookies1758

stored by Firefox, before testing your solution, so that you don't run into problems1765

where you are not actually starting a new session when you first log into your website.1769

And the way, again, to do that is: if you go to Firefox, and then Options, if you click on the Privacy tab,1778

Remove individual cookies, you can search for any localhost cookies.1784

And here there are none, but you would just select them and click to remove them.1789

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

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

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

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • 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 lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.