0% found this document useful (0 votes)
52 views25 pages

PHP Lesson2Slides

This document summarizes a lesson on cookies and PHP sessions presented by Julian Quirke. It begins with an overview of cookies, including what they are, why they are used, how they are created in PHP, and their components. It then covers PHP sessions, explaining that they are similar to cookies but store data on the server rather than in the browser. The lesson demonstrates creating and retrieving session data across multiple pages in PHP. It concludes by advertising the next lesson on error handling and advanced PHP development techniques.

Uploaded by

bernbilazon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views25 pages

PHP Lesson2Slides

This document summarizes a lesson on cookies and PHP sessions presented by Julian Quirke. It begins with an overview of cookies, including what they are, why they are used, how they are created in PHP, and their components. It then covers PHP sessions, explaining that they are similar to cookies but store data on the server rather than in the browser. The lesson demonstrates creating and retrieving session data across multiple pages in PHP. It concludes by advertising the next lesson on error handling and advanced PHP development techniques.

Uploaded by

bernbilazon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Diploma in Web

Development – Part II
PHP Development – Week 2
Cookies & PHP Sessions

Presented by:
Julian Quirke
Web Development Educator

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Week 1 Recap

Object-Oriented PHP
➢ Introduction to PHP
➢ PHP Class Overview
➢ Magic Methods

➢ Summary
➢ Q&A

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Today’s Lesson

Cookies & PHP Sessions


➢ What is a Cookie?
➢ Creating PHP Sessions
➢ PHP Session Demo

➢ Summary
➢ Q&A

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Let’s Begin!

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?

Cookies

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?

Cookie
is a piece of data sent from a web application that is
stored on the client’s web browser

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?

➢ Allow information to be “remembered” across


multiple web pages

➢ Cookies are stored in the user’s browser

➢ Sent with every HTTP request

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Why Use Cookies?

➢ Originally developed to remember


“stateful” information
➢ (Internet Protocols are by default stateless)
➢ E.G.
➢ Shopping Cart data
➢ Remember already visited pages
➢ Much more

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Why Use Cookies?

➢ Cookies can be used for user


authentication
➢ Can create a “stateful” web application from
a stateless internet
➢ Data tracking for advertising
➢ User settings

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Makeup of a Cookie
Contains:
➢ Name
➢ cookie’s name (much like a variable name)
➢ Value
➢ cookie’s value (much like a variable value)
➢ Attributes
➢ meta information about the cookie
➢ Domain, Path, Expires, Secure, HTTP Only

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP

Name of Cookie (string)

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP
Value of Cookie (string)
Default = “”

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP

Expiry Date (int)


Default = 0

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP
Available in Paths (string)
Default = “”

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP

Available in Domain (string)


Default = “”

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP
Requires encrypted (bool)
Default = FALSE

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
What is a Cookie?
Creating a Cookie in PHP

Only accessible by HTTP Request (bool)


Default = FALSE

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Creating PHP Sessions

PHP Session

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Creating PHP Sessions

PHP Session
is a method of storing stateful information in the
form of PHP variables to be used across multiple
web pages

(Sounds like a cookie…)

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Creating PHP Sessions
Sessions
➢ Session variables are stored on the
server!

➢ End by default when a user closes


browser

➢ Recalls user with cookies by default


➢ GET variables are backup option (less secure)

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Creating PHP Sessions
Sessions

➢ Start/Retrieve with “session_start()”


function
➢ Access session variables through global
“$_SESSION[]”

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Creating PHP Sessions
Session Example:

On a different web page:

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
PHP Session Demo

Session Demo

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Next Week
PHP Development Semester
➢ The next session is “Error Handling & Advanced Development”
• Member Visibility
• Abstract Classes & Interfaces
• Error Handling in PHP

➢ Recordings are available within 24 hours after the live webinar

➢ Go to www.shawacademy.com and then the Top Right Corner – Members Area

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator
Q&A
Next Lesson is

Error Handling & Advanced Development


➢ Learn advanced processed used in building
encapsulated, self-monitoring classes &
applications
www.shawacademy.com
➢ You will understand the value of managing
www.facebook.com/shawacademy
member visibility & the purpose of custom error
www.twitter.com/shawacademy
handling
[email protected]

Julian Quirke ADVANCED WEB DEVELOPMENT


Web Development Educator

You might also like