SlideShare une entreprise Scribd logo
1  sur  27
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Hidaya Institute of
Science &
Technology
www.histpk.org
A Division of Hidaya Trust, Pakistan
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
COOKIES
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Did you know?
“ Cookies were invented by Netscape, which
wanted to use them for creating a shopping cart for
an online shop. Thanks to cookies people were
able to keep items in their cart, even after
disconnecting from the shop. ”
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• What are Cookies?
• What information Cookies Store?
• Why Cookies are Needed?
• How to Enable Cookies?
• How Cookies Work?
• Where Cookies Reside?
• Types of Cookies
• Malicious Cookie Usage
Topics To be Covered
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Lecture# 1
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• A little piece of data that is stored in a file (format
depends on browser) on the user / client machine.
• On the request of a webserver, your browser creates
such a file (cookie).
• Each time the user goes to a webpage this (cookie)
information can be requested by the webpage.
• The webserver can read and write content from and to
this file.
What are Cookies?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Cookie can hold any information, but usually
applications use cookies to store user's specific
information (login, encrypted password, last visited date,
etc).
What information Cookies Store?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
When dealing with cookies, you should be aware of some
ground rules:
• Cookies are used to record information about your activities
on a particular domain, therefore they can only be read / write
by the domain that created them and their subdomains.
• According to the HTTP protocol, cookies can’t be larger than
4096 Bytes (4KB) each.
• Usually, A maximum of 20 cookies can be stored on a user’s
PC / Client per domain, but may differ on different browser.
• Usually total number of cookies on the client’s harddrive is
limited to around 300 cookies. This may also differ per
browser.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• Cookies are typically needed to bypass the stateless
nature of the HTTP protocol, by using the client’s
disk as a storage area for permanent data.
• However, they’re dependent on the client browser
being configured to accept cookies.
Why Cookies are Needed?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Chrome:
•Click the wrench icon.
•Select Settings.
•Click Show advanced settings.
•Click Content settings in the "Privacy" section.
•Select Allow local data to be set to allow both first-party and third-
party cookies. If you only want to accept first-party cookies, check the
box next to "Block all third-party cookies without exception."
How to Enable Cookies?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Mozilla Firefox 3.x for Windows:
• Click Tools > Options.
• Click Privacy in the top panel.
• Set "Firefox will:" to Use custom settings for history.
• Check the box next to "Accept cookies from sites" to enable
cookies.
• Click OK.
How to Enable Cookies? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Mozilla Firefox 2.x for Windows:
• Click Tools > Options.
• Click Privacy in the top panel.
• Select the checkbox labeled "Accept cookies from sites."
• Click OK.
How to Enable Cookies? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Internet Explorer 7 or 8:
• Click Start > Control Panel. (With Windows XP Classic View, click
the Windows Start button >Settings > Control Panel).
• Double-click the Internet Options icon.
• Select the Privacy tab and Click Advanced.
• Select "Override automatic cookie handling" under the "Cookies"
section in the Advanced Privacy Settings window.
• Select the "Accept" or "Prompt" option under "First-party Cookies."
• Select the "Accept" or "Prompt" option under "Third-party Cookies."
(If you select the "Prompt" option, you'll be asked for approval every
time a website attempts to send you a cookie.)
• In the Internet Options window, click OK to exit.
How to Enable Cookies? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Internet Explorer 6:
• Click Start > Control Panel. (With Windows XP Classic View, click
the Windows Start button >Settings > Control Panel).
• Click Advanced.
• Select "Override Automatic Cookie Handling."
• Select the "Accept" or "Prompt" option under "First-party Cookies."
• Select the "Accept" or "Prompt" option under "Third-party Cookies."
(If you select the "Prompt" option, you'll be asked for approval every
time a website attempts to send you a cookie.)
• In the Internet Options window, click OK to exit.
How to Enable Cookies? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
To enable cookies in Safari:
• Go to the Safari drop-down menu.
• Select Preferences.
• Click Security in the top panel.
• Under "Accept Cookies" select Only from sites you navigate to.
How to Enable Cookies? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• Setcookie() is to let the browser know that the server
would like to create a new cookie.
• Use $_COOKIE variable (array) to retrieve a cookie.
How it works:
1) initial state, just before user opens some-page.php in
the browser.
$_COOKIE array is empty at this point.
No cookie in the browser at this point.
How Cookies Work?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
2) some-page.php sets cookie named "my-cookie" via
setcookie php function, and cookie goes to the browser
along with page content
$_COOKIE array is still empty at this point.
Browser has cookie "my-cookie" at this point.
3) next time user opens some-page.php (or after refresh)
$_COOKIE array now contains "my-cookie".
Browser still has cookie "my-cookie".
How Cookies Work? (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• In Google Chrome:
– Windows XP:
C:Users<USERNAME> Local SettingsApplication DataGoogle
ChromeUser Data
– Windows Vista & 7:
C:Users<USERNAME> AppDataLocalGoogleChromeUser
Datadefault
Shortcut: Go to Start -> run -> type “%USERPROFILE%”
this will view you the current user folder
Where Cookies Reside?
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
“ The most important thing to remember, when
creating a cookie in PHP, is that you must set all cookies
before you send any data to the browser. This means
that you should always initialise new cookies before any
output. This includes echo() or print() commands, and
the <html> or <body> tags. Of course, there are some
exceptions, but this is a general rule of thumb. ”
Before Setting Cookie
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• Session Cookies
• Persistent Cookies
Types of Cookies
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Session Cookies
• Session cookie is also called Temporary cookie
• Session cookie is stored only for your current
browsing session, and is deleted from your
computer when you close your browser.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
setcookie() function is use to create the cookie
bool setcookie ( string name [, string value])
• name: This argument sets the name of the cookie.
for example setcookie(‘mycookie’, …) will set mycookie and is called
$_COOKIE['mycookie'] at server side.
• value: This will set the value of the cookie. Since this values is
stored on the client browser extra care must be taken that it does
not store some secure information e.g non-encrypted passwords.
The value is accessed by $_COOKIE['mycookie'] at the web server.
• All the attributes are optional, only the first (name) is not optional.
Session Cookies (contd…)
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
<?php
setcookie(‘username‘,’admin’);
?>
<?php
echo $_COOKIE[‘username’];
?>
Setting and Retrieving Cookies
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• Once a cookie has been set for a domain, it becomes available in the special
$_COOKIE associative array, and its value may be accessed using standard array
notation.
<?php
// if cookie present, use it
// else display generic message
if ($_COOKIE['username'])
{
echo "Welcome back, " . $_COOKIE['username'];
}
else
{
echo “You are not signed in";
}
?>
• To check whether your cookies are working correctly, use the statement <?php
print_r($_COOKIE); ?> to look inside PHP’s special $_COOKIE array.
Retrieving Cookie Data
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• Only strings can be stored in Cookie files.
• To store an array in a cookie, convert it to a string by using the
serialize() PHP function.
• The array can be reconstructed using the unserialize() function
once it had been read back in.
• Remember cookie size is limited!
NOTE: You really shouldn't use (un)serialize with cookies
without encoding them. An evil user could inject ANY code in
your script.
Use of encoding:
e.g: base64_encode(serialize(cookie_data))
Storing an array..
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
1. Change Background & foreground (text) color of
webpage. Store their information in Cookies to retain
changes.
2. Make Email Box, user login (use cookies in login). On
Welcome page, should have compose email, inbox,
drafts, sent, trash. Make complete Email Box System.
Note: Emails should be stored in database.
Assignments
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Username:
Password:
ali@yahoo.com
……….
Login
Enter
Username &
Password
Click
Compose
Inbox
Sent
Trash
Draft
Welcome “Ali”
Email System
To
Sub
Cc
Message
Send
Compose
Inbox
Sent
Trash
Draft
Welcome “Ali”
Email System
Check Name SubjectCheck Name Subject
Ali GreetingsAli Greetings
Ahmed WorkAhmed Work
Aslam AssignmentAslam Assignment
Delete
Compose
Inbox
Sent
Trash
Draft
Welcome “Ali”
Email System
Check Name SubjectCheck Name Subject
Ali Greetings ReplyAli Greetings Reply
Ahmed WorkAhmed Work
Aslam AssignmentAslam Assignment
Delete
Compose
Inbox
Sent
Trash
Draft
Welcome “Ali”
Email System
Check Name SubjectCheck Name Subject
Ali GreetingsAli Greetings
Ahmed WorkAhmed Work
Aslam AssignmentAslam Assignment
Delete

Contenu connexe

Tendances

Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scriptingArghodeepPaul
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteAl-Mamun Sarkar
 
File based approach
File based approachFile based approach
File based approachPreethaAS
 
Operating system 22 threading issues
Operating system 22 threading issuesOperating system 22 threading issues
Operating system 22 threading issuesVaibhav Khanna
 
File organization and introduction of DBMS
File organization and introduction of DBMSFile organization and introduction of DBMS
File organization and introduction of DBMSVrushaliSolanke
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...Pallavi Seth
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmsPiyush Rochwani
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Memory management ppt
Memory management pptMemory management ppt
Memory management pptManishaJha43
 
Database Fundamental
Database FundamentalDatabase Fundamental
Database FundamentalGong Haibing
 
Backup & recovery with rman
Backup & recovery with rmanBackup & recovery with rman
Backup & recovery with rmanitsabidhussain
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systemsvampugani
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oraclesadegh salehi
 

Tendances (20)

Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scripting
 
Java swing
Java swingJava swing
Java swing
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Io streams
Io streamsIo streams
Io streams
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Directory structure
Directory structureDirectory structure
Directory structure
 
MySQL constraints
MySQL constraintsMySQL constraints
MySQL constraints
 
File based approach
File based approachFile based approach
File based approach
 
Operating system 22 threading issues
Operating system 22 threading issuesOperating system 22 threading issues
Operating system 22 threading issues
 
File organization and introduction of DBMS
File organization and introduction of DBMSFile organization and introduction of DBMS
File organization and introduction of DBMS
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Memory management
Memory managementMemory management
Memory management
 
Memory management ppt
Memory management pptMemory management ppt
Memory management ppt
 
Database Fundamental
Database FundamentalDatabase Fundamental
Database Fundamental
 
Backup & recovery with rman
Backup & recovery with rmanBackup & recovery with rman
Backup & recovery with rman
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oracle
 
Disk management
Disk managementDisk management
Disk management
 

Similaire à Cookies in php lecture 1

Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2Mudasir Syed
 
Presentation on Internet Cookies
Presentation on Internet CookiesPresentation on Internet Cookies
Presentation on Internet CookiesRitika Barethia
 
Cookies: A brief Introduction
Cookies: A brief IntroductionCookies: A brief Introduction
Cookies: A brief IntroductionHTS Hosting
 
What is digital marketing by prof. (Dr.) Gaurav Sood
What is digital marketing by prof. (Dr.) Gaurav SoodWhat is digital marketing by prof. (Dr.) Gaurav Sood
What is digital marketing by prof. (Dr.) Gaurav SoodGaurav Sood
 
Cookie testing
Cookie testingCookie testing
Cookie testingBugRaptors
 
07 cookies
07 cookies07 cookies
07 cookiessnopteck
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2sandeep54552
 
Mozilla firefox support phone number
Mozilla firefox support phone numberMozilla firefox support phone number
Mozilla firefox support phone numberwilliampaul108
 
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s SakeWhat Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s SakePiwik PRO
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanismJivan Nepali
 
The ultimate guide to mining bitcoin with cryptotab
The ultimate guide to mining bitcoin with cryptotabThe ultimate guide to mining bitcoin with cryptotab
The ultimate guide to mining bitcoin with cryptotabSaid Dhaouadi
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsSukrit Gupta
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Chhom Karath
 

Similaire à Cookies in php lecture 1 (20)

Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Presentation on Internet Cookies
Presentation on Internet CookiesPresentation on Internet Cookies
Presentation on Internet Cookies
 
GDPR Cookies Policy
GDPR Cookies PolicyGDPR Cookies Policy
GDPR Cookies Policy
 
Cookies: A brief Introduction
Cookies: A brief IntroductionCookies: A brief Introduction
Cookies: A brief Introduction
 
What is digital marketing by prof. (Dr.) Gaurav Sood
What is digital marketing by prof. (Dr.) Gaurav SoodWhat is digital marketing by prof. (Dr.) Gaurav Sood
What is digital marketing by prof. (Dr.) Gaurav Sood
 
Cookie testing
Cookie testingCookie testing
Cookie testing
 
07 cookies
07 cookies07 cookies
07 cookies
 
Cookies
CookiesCookies
Cookies
 
16 cookies
16 cookies16 cookies
16 cookies
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
 
Data Mining - GCPCUG May 2011
Data Mining - GCPCUG May 2011Data Mining - GCPCUG May 2011
Data Mining - GCPCUG May 2011
 
Mozilla firefox support phone number
Mozilla firefox support phone numberMozilla firefox support phone number
Mozilla firefox support phone number
 
APEX & Cookie Monster
APEX & Cookie MonsterAPEX & Cookie Monster
APEX & Cookie Monster
 
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s SakeWhat Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Internet cookies
Internet cookiesInternet cookies
Internet cookies
 
The ultimate guide to mining bitcoin with cryptotab
The ultimate guide to mining bitcoin with cryptotabThe ultimate guide to mining bitcoin with cryptotab
The ultimate guide to mining bitcoin with cryptotab
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
Internet cookies
Internet cookiesInternet cookies
Internet cookies
 

Plus de Mudasir Syed

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1 Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminMudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions Mudasir Syed
 
Form validation server side
Form validation server side Form validation server side
Form validation server side Mudasir Syed
 

Plus de Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Ajax
Ajax Ajax
Ajax
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
 

Dernier

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Dernier (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Cookies in php lecture 1

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org COOKIES
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Did you know? “ Cookies were invented by Netscape, which wanted to use them for creating a shopping cart for an online shop. Thanks to cookies people were able to keep items in their cart, even after disconnecting from the shop. ”
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • What are Cookies? • What information Cookies Store? • Why Cookies are Needed? • How to Enable Cookies? • How Cookies Work? • Where Cookies Reside? • Types of Cookies • Malicious Cookie Usage Topics To be Covered
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Lecture# 1
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • A little piece of data that is stored in a file (format depends on browser) on the user / client machine. • On the request of a webserver, your browser creates such a file (cookie). • Each time the user goes to a webpage this (cookie) information can be requested by the webpage. • The webserver can read and write content from and to this file. What are Cookies?
  • 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Cookie can hold any information, but usually applications use cookies to store user's specific information (login, encrypted password, last visited date, etc). What information Cookies Store?
  • 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org When dealing with cookies, you should be aware of some ground rules: • Cookies are used to record information about your activities on a particular domain, therefore they can only be read / write by the domain that created them and their subdomains. • According to the HTTP protocol, cookies can’t be larger than 4096 Bytes (4KB) each. • Usually, A maximum of 20 cookies can be stored on a user’s PC / Client per domain, but may differ on different browser. • Usually total number of cookies on the client’s harddrive is limited to around 300 cookies. This may also differ per browser.
  • 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • Cookies are typically needed to bypass the stateless nature of the HTTP protocol, by using the client’s disk as a storage area for permanent data. • However, they’re dependent on the client browser being configured to accept cookies. Why Cookies are Needed?
  • 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Chrome: •Click the wrench icon. •Select Settings. •Click Show advanced settings. •Click Content settings in the "Privacy" section. •Select Allow local data to be set to allow both first-party and third- party cookies. If you only want to accept first-party cookies, check the box next to "Block all third-party cookies without exception." How to Enable Cookies?
  • 11. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Mozilla Firefox 3.x for Windows: • Click Tools > Options. • Click Privacy in the top panel. • Set "Firefox will:" to Use custom settings for history. • Check the box next to "Accept cookies from sites" to enable cookies. • Click OK. How to Enable Cookies? (contd…)
  • 12. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Mozilla Firefox 2.x for Windows: • Click Tools > Options. • Click Privacy in the top panel. • Select the checkbox labeled "Accept cookies from sites." • Click OK. How to Enable Cookies? (contd…)
  • 13. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Internet Explorer 7 or 8: • Click Start > Control Panel. (With Windows XP Classic View, click the Windows Start button >Settings > Control Panel). • Double-click the Internet Options icon. • Select the Privacy tab and Click Advanced. • Select "Override automatic cookie handling" under the "Cookies" section in the Advanced Privacy Settings window. • Select the "Accept" or "Prompt" option under "First-party Cookies." • Select the "Accept" or "Prompt" option under "Third-party Cookies." (If you select the "Prompt" option, you'll be asked for approval every time a website attempts to send you a cookie.) • In the Internet Options window, click OK to exit. How to Enable Cookies? (contd…)
  • 14. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Internet Explorer 6: • Click Start > Control Panel. (With Windows XP Classic View, click the Windows Start button >Settings > Control Panel). • Click Advanced. • Select "Override Automatic Cookie Handling." • Select the "Accept" or "Prompt" option under "First-party Cookies." • Select the "Accept" or "Prompt" option under "Third-party Cookies." (If you select the "Prompt" option, you'll be asked for approval every time a website attempts to send you a cookie.) • In the Internet Options window, click OK to exit. How to Enable Cookies? (contd…)
  • 15. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org To enable cookies in Safari: • Go to the Safari drop-down menu. • Select Preferences. • Click Security in the top panel. • Under "Accept Cookies" select Only from sites you navigate to. How to Enable Cookies? (contd…)
  • 16. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • Setcookie() is to let the browser know that the server would like to create a new cookie. • Use $_COOKIE variable (array) to retrieve a cookie. How it works: 1) initial state, just before user opens some-page.php in the browser. $_COOKIE array is empty at this point. No cookie in the browser at this point. How Cookies Work?
  • 17. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 2) some-page.php sets cookie named "my-cookie" via setcookie php function, and cookie goes to the browser along with page content $_COOKIE array is still empty at this point. Browser has cookie "my-cookie" at this point. 3) next time user opens some-page.php (or after refresh) $_COOKIE array now contains "my-cookie". Browser still has cookie "my-cookie". How Cookies Work? (contd…)
  • 18. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • In Google Chrome: – Windows XP: C:Users<USERNAME> Local SettingsApplication DataGoogle ChromeUser Data – Windows Vista & 7: C:Users<USERNAME> AppDataLocalGoogleChromeUser Datadefault Shortcut: Go to Start -> run -> type “%USERPROFILE%” this will view you the current user folder Where Cookies Reside?
  • 19. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org “ The most important thing to remember, when creating a cookie in PHP, is that you must set all cookies before you send any data to the browser. This means that you should always initialise new cookies before any output. This includes echo() or print() commands, and the <html> or <body> tags. Of course, there are some exceptions, but this is a general rule of thumb. ” Before Setting Cookie
  • 20. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • Session Cookies • Persistent Cookies Types of Cookies
  • 21. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Session Cookies • Session cookie is also called Temporary cookie • Session cookie is stored only for your current browsing session, and is deleted from your computer when you close your browser.
  • 22. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org setcookie() function is use to create the cookie bool setcookie ( string name [, string value]) • name: This argument sets the name of the cookie. for example setcookie(‘mycookie’, …) will set mycookie and is called $_COOKIE['mycookie'] at server side. • value: This will set the value of the cookie. Since this values is stored on the client browser extra care must be taken that it does not store some secure information e.g non-encrypted passwords. The value is accessed by $_COOKIE['mycookie'] at the web server. • All the attributes are optional, only the first (name) is not optional. Session Cookies (contd…)
  • 23. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org <?php setcookie(‘username‘,’admin’); ?> <?php echo $_COOKIE[‘username’]; ?> Setting and Retrieving Cookies
  • 24. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • Once a cookie has been set for a domain, it becomes available in the special $_COOKIE associative array, and its value may be accessed using standard array notation. <?php // if cookie present, use it // else display generic message if ($_COOKIE['username']) { echo "Welcome back, " . $_COOKIE['username']; } else { echo “You are not signed in"; } ?> • To check whether your cookies are working correctly, use the statement <?php print_r($_COOKIE); ?> to look inside PHP’s special $_COOKIE array. Retrieving Cookie Data
  • 25. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • Only strings can be stored in Cookie files. • To store an array in a cookie, convert it to a string by using the serialize() PHP function. • The array can be reconstructed using the unserialize() function once it had been read back in. • Remember cookie size is limited! NOTE: You really shouldn't use (un)serialize with cookies without encoding them. An evil user could inject ANY code in your script. Use of encoding: e.g: base64_encode(serialize(cookie_data)) Storing an array..
  • 26. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 1. Change Background & foreground (text) color of webpage. Store their information in Cookies to retain changes. 2. Make Email Box, user login (use cookies in login). On Welcome page, should have compose email, inbox, drafts, sent, trash. Make complete Email Box System. Note: Emails should be stored in database. Assignments
  • 27. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Username: Password: ali@yahoo.com ………. Login Enter Username & Password Click Compose Inbox Sent Trash Draft Welcome “Ali” Email System To Sub Cc Message Send Compose Inbox Sent Trash Draft Welcome “Ali” Email System Check Name SubjectCheck Name Subject Ali GreetingsAli Greetings Ahmed WorkAhmed Work Aslam AssignmentAslam Assignment Delete Compose Inbox Sent Trash Draft Welcome “Ali” Email System Check Name SubjectCheck Name Subject Ali Greetings ReplyAli Greetings Reply Ahmed WorkAhmed Work Aslam AssignmentAslam Assignment Delete Compose Inbox Sent Trash Draft Welcome “Ali” Email System Check Name SubjectCheck Name Subject Ali GreetingsAli Greetings Ahmed WorkAhmed Work Aslam AssignmentAslam Assignment Delete