SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
Introduction to PHP
Web programming
Week 11, day2
Cookies
Cookies
• HTTP is a stateless protocol; this means that the web server does not know
(or care) whether two requests comes from the same user or not; it just
handles each request without regard to the context in which it happens.
• Cookies are used to maintain the state in between requests—even when
they occur at large time intervals from each other.
• Cookies allow your applications to store a small amount of textual data
(typically,4-6kB) on a Web client browser.
• There are a number of possible uses for cookies, although their most
common one is maintaining state of a user
Creating cookie
• setcookie(‚userid", "100", time() + 86400);
• This simply sets a cookie variable named ‚userid‛ with value ‚100‛
and this variable value will be available till next 86400 seconds
from current time
Cookie variable name
variable value
Expiration time.
Accessing Cookies
• echo $_COOKIE*’userid’+; // prints 100
• Cookie as array
– setcookie("test_cookie[0]", "foo");
– setcookie("test_cookie[1]", "bar");
– setcookie("test_cookie[2]", "bar");
• var_dump($_COOKIE*‘test_cookie’+);
Destroying Cookies
• There is no special methods to destroy a cookie, We achieve it by
setting the cookie time into a past time so that it destroys it
–Eg : setcookie(‘userid’,100,time()-100);
Sessions
Sessions
• Session serve the same purpose of cookies that is sessions are used
to maintain the state in between requests
• Session can be started in two ways in PHP
1. By changing the session.auto_start configuration setting in php.ini
2. Calling session_start() on the beginning of each pages wherever you
use session(Most common way)
Note: session_start() must be called before any output is sent to the browser
Creating and accessing session
• Once session is started you can create and access session variables
like any other arrays in PHP
– $_SESSION[‘userid’+ = 100;
– echo $_SESSION*‘userid’+; //prints 100
Session variable name variable value
Destroying session
• There are two methods to destroy a session variable
1. Using unset() function
• Eg unsset($_SESSION*‘userid’+)
2. Calling session_destroy() method. This will effectively destroy all the
session variables. So for deleting only one variable you should go for
the previous method
• Session_destroy()
Comparison
 cookies are stored in the user's
browser
 A cookie can keep information in the
user's browser until deleted by user or set
as per the timer. It will not be destroyed
even if you close the browser.
 Cookies can only store string
 we can save cookie for future reference
 Sessions are stored in server
 A session is available as long as the
browser is opened. User cant disable the
session. It will be destroyed if you close the
browser
 Can store not only strings but also
objects
 session cant be.
Cookies Session
HTTP Headers
Headers - Redirection
• The most common use of headers is to redirect the user to another
page. To do this,we use the Location header:
Eg: header("Location: http://phparch.com");
• header() must be called before any other output, including any
whitespace characters outside of PHP tags, as well as all HTML
data.
• If you fail to abide by this rule, two things will happen: your
header will have no effect, and PHP may output an error.
Questions?
‚A good question deserve a good grade…‛
End of day
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Más contenido relacionado

La actualidad más candente (20)

Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Sessions and cookies in php
Sessions and cookies in phpSessions and cookies in php
Sessions and cookies in php
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
Cookies & Session
Cookies & SessionCookies & Session
Cookies & Session
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Xml
XmlXml
Xml
 
Jquery
JqueryJquery
Jquery
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Html
HtmlHtml
Html
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Xhtml
XhtmlXhtml
Xhtml
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 

Destacado

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingAhmed Swilam
 
Php Coding Convention
Php Coding ConventionPhp Coding Convention
Php Coding ConventionPhuong Vy
 
開始網站設計
開始網站設計開始網站設計
開始網站設計資彥 解
 
MySQL資料庫設計規劃與phpMyAdmin
MySQL資料庫設計規劃與phpMyAdminMySQL資料庫設計規劃與phpMyAdmin
MySQL資料庫設計規劃與phpMyAdmin資彥 解
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1Kanchilug
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introductionProgrammer Blog
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive OverviewMohamed Loey
 
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...資彥 解
 
Pakistan's mountain ranges
Pakistan's mountain rangesPakistan's mountain ranges
Pakistan's mountain rangestehseen bukhari
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationGerard Sychay
 

Destacado (20)

Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Coding In Php
Coding In PhpCoding In Php
Coding In Php
 
Php Coding Convention
Php Coding ConventionPhp Coding Convention
Php Coding Convention
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
開始網站設計
開始網站設計開始網站設計
開始網站設計
 
MySQL資料庫設計規劃與phpMyAdmin
MySQL資料庫設計規劃與phpMyAdminMySQL資料庫設計規劃與phpMyAdmin
MySQL資料庫設計規劃與phpMyAdmin
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Php course-syllabus
Php course-syllabusPhp course-syllabus
Php course-syllabus
 
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
 
Pakistan's mountain ranges
Pakistan's mountain rangesPakistan's mountain ranges
Pakistan's mountain ranges
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and Authentication
 

Similar a Introduction to php web programming - sessions and cookies

PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSDegu8
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erickokelloerick
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuerySIVAKUMAR V
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptSreejithVP7
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfHumphreyOwuor1
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Hassen Poreya
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servletsvishal choudhary
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptxssuser4a97d3
 
Php file upload, cookies & session
Php file upload, cookies & sessionPhp file upload, cookies & session
Php file upload, cookies & sessionJamshid Hashimi
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxShitalGhotekar
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptxITNet
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In PhpHarit Kothari
 
javaScriptCookies.pptx
javaScriptCookies.pptxjavaScriptCookies.pptx
javaScriptCookies.pptxMattMarino13
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)kunjan shah
 
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
 
Php 07-cookies-sessions
Php 07-cookies-sessionsPhp 07-cookies-sessions
Php 07-cookies-sessionsYUSRA FERNANDO
 

Similar a Introduction to php web programming - sessions and cookies (20)

PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
 
Php file upload, cookies & session
Php file upload, cookies & sessionPhp file upload, cookies & session
Php file upload, cookies & session
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptx
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptx
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
16 cookies
16 cookies16 cookies
16 cookies
 
javaScriptCookies.pptx
javaScriptCookies.pptxjavaScriptCookies.pptx
javaScriptCookies.pptx
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
 
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)
 
Php 07-cookies-sessions
Php 07-cookies-sessionsPhp 07-cookies-sessions
Php 07-cookies-sessions
 
S8-Session Managment
S8-Session ManagmentS8-Session Managment
S8-Session Managment
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 

Último

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Último (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Introduction to php web programming - sessions and cookies

  • 1. Introduction to PHP Web programming Week 11, day2
  • 3. Cookies • HTTP is a stateless protocol; this means that the web server does not know (or care) whether two requests comes from the same user or not; it just handles each request without regard to the context in which it happens. • Cookies are used to maintain the state in between requests—even when they occur at large time intervals from each other. • Cookies allow your applications to store a small amount of textual data (typically,4-6kB) on a Web client browser. • There are a number of possible uses for cookies, although their most common one is maintaining state of a user
  • 4. Creating cookie • setcookie(‚userid", "100", time() + 86400); • This simply sets a cookie variable named ‚userid‛ with value ‚100‛ and this variable value will be available till next 86400 seconds from current time Cookie variable name variable value Expiration time.
  • 5. Accessing Cookies • echo $_COOKIE*’userid’+; // prints 100 • Cookie as array – setcookie("test_cookie[0]", "foo"); – setcookie("test_cookie[1]", "bar"); – setcookie("test_cookie[2]", "bar"); • var_dump($_COOKIE*‘test_cookie’+);
  • 6. Destroying Cookies • There is no special methods to destroy a cookie, We achieve it by setting the cookie time into a past time so that it destroys it –Eg : setcookie(‘userid’,100,time()-100);
  • 8. Sessions • Session serve the same purpose of cookies that is sessions are used to maintain the state in between requests • Session can be started in two ways in PHP 1. By changing the session.auto_start configuration setting in php.ini 2. Calling session_start() on the beginning of each pages wherever you use session(Most common way) Note: session_start() must be called before any output is sent to the browser
  • 9. Creating and accessing session • Once session is started you can create and access session variables like any other arrays in PHP – $_SESSION[‘userid’+ = 100; – echo $_SESSION*‘userid’+; //prints 100 Session variable name variable value
  • 10. Destroying session • There are two methods to destroy a session variable 1. Using unset() function • Eg unsset($_SESSION*‘userid’+) 2. Calling session_destroy() method. This will effectively destroy all the session variables. So for deleting only one variable you should go for the previous method • Session_destroy()
  • 11. Comparison  cookies are stored in the user's browser  A cookie can keep information in the user's browser until deleted by user or set as per the timer. It will not be destroyed even if you close the browser.  Cookies can only store string  we can save cookie for future reference  Sessions are stored in server  A session is available as long as the browser is opened. User cant disable the session. It will be destroyed if you close the browser  Can store not only strings but also objects  session cant be. Cookies Session
  • 13. Headers - Redirection • The most common use of headers is to redirect the user to another page. To do this,we use the Location header: Eg: header("Location: http://phparch.com"); • header() must be called before any other output, including any whitespace characters outside of PHP tags, as well as all HTML data. • If you fail to abide by this rule, two things will happen: your header will have no effect, and PHP may output an error.
  • 14. Questions? ‚A good question deserve a good grade…‛
  • 16. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 17. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com