SlideShare a Scribd company logo
© 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

More Related Content

What's hot

Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
FazalRehman79
 
Sql operator
Sql operatorSql operator
Sql operator
Pooja Dixit
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
Himanshu Kesharwani
 
Digital Search Tree
Digital Search TreeDigital Search Tree
Digital Search Tree
East West University
 
Stack
StackStack
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQL
Dag H. Wanvik
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
MySQLi
MySQLiMySQLi
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
Abirami A
 
data structure
data structuredata structure
data structure
hashim102
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Circular Queue data structure
Circular Queue data structureCircular Queue data structure
Circular Queue data structure
Dhananjaysinh Jhala
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
pavankumarjakkepalli
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 

What's hot (20)

Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Array data structure
Array data structureArray data structure
Array data structure
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
Sql operator
Sql operatorSql operator
Sql operator
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Digital Search Tree
Digital Search TreeDigital Search Tree
Digital Search Tree
 
Stack
StackStack
Stack
 
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQL
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
MySQLi
MySQLiMySQLi
MySQLi
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
 
data structure
data structuredata structure
data structure
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
 
Circular Queue data structure
Circular Queue data structureCircular Queue data structure
Circular Queue data structure
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 

Similar to Cookies in php lecture 1

Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
Mudasir Syed
 
Presentation on Internet Cookies
Presentation on Internet CookiesPresentation on Internet Cookies
Presentation on Internet Cookies
Ritika Barethia
 
GDPR Cookies Policy
GDPR Cookies PolicyGDPR Cookies Policy
GDPR Cookies Policy
GDPR Privacy Policy
 
Cookies: A brief Introduction
Cookies: A brief IntroductionCookies: A brief Introduction
Cookies: A brief Introduction
HTS 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 Sood
Gaurav Sood
 
Cookie testing
Cookie testingCookie testing
Cookie testing
BugRaptors
 
07 cookies
07 cookies07 cookies
07 cookies
snopteck
 
Cookies
CookiesCookies
16 cookies
16 cookies16 cookies
16 cookies
Abhijit Gaikwad
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
sandeep54552
 
Data Mining - GCPCUG May 2011
Data Mining - GCPCUG May 2011Data Mining - GCPCUG May 2011
Data Mining - GCPCUG May 2011
Greater Cleveland PC Users Group
 
Mozilla firefox support phone number
Mozilla firefox support phone numberMozilla firefox support phone number
Mozilla firefox support phone number
williampaul108
 
APEX & Cookie Monster
APEX & Cookie MonsterAPEX & Cookie Monster
APEX & Cookie Monster
Christian Rokitta
 
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
Piwik PRO
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
Jivan Nepali
 
Internet cookies
Internet cookiesInternet cookies
Internet cookies
Abhi Bhardwaj
 
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
Said Dhaouadi
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Sukrit 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
 
Internet cookies
Internet cookiesInternet cookies
Internet cookies
Abhi Bhardwaj
 

Similar to 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
 

More from Mudasir Syed

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
Mudasir Syed
 
Ajax
Ajax Ajax
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
Mudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
Mudasir Syed
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
Mudasir Syed
 
Sql select
Sql select Sql select
Sql select
Mudasir Syed
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
Mudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
Mudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir 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.1
Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
Mudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
Mudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
Mudasir 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
 

More from 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
 

Recently uploaded

A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 

Recently uploaded (20)

A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 

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