0% found this document useful (0 votes)
308 views

State Management in PHP

This document discusses different methods of state management in client-server programming using PHP. It defines state management as managing information about a client between HTTP requests to a server. The three main methods covered are cookies, sessions, and URL rewriting/query strings. Cookies store information in small temporary files on the client side. Sessions store information on the server side for each client. Query strings communicate information in the URL. Examples are given of how each method can be used to maintain a user's login information and shopping cart contents across multiple requests.

Uploaded by

Hemant Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
308 views

State Management in PHP

This document discusses different methods of state management in client-server programming using PHP. It defines state management as managing information about a client between HTTP requests to a server. The three main methods covered are cookies, sessions, and URL rewriting/query strings. Cookies store information in small temporary files on the client side. Sessions store information on the server side for each client. Query strings communicate information in the URL. Examples are given of how each method can be used to maintain a user's login information and shopping cart contents across multiple requests.

Uploaded by

Hemant Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

State Management in

Client-Server Programming
This is Guideline PPT
It is needed to do experiments
Read detailed concept whenever
required.

By Hemant N Yadav
Agenda
• Definition of State Management
• Example of State management
• State management in PHP using Cookie
• State management in PHP using Session
• State management in PHP using URL-
Rewriting/ Query String

By Hemant N Yadav
Definition
• Management of information about client between
different http request to server known as State
management.
• Some methods are:
– Cookie: Information in small temporary files at client side
created by server and sent to server with each request.
– Session: Information in small temporary files at server side
created by server and maintained by server for each client.
– Query String/ URL Re-writing: Information about client
communicated in URL as Query string
– …… Some others are also. But we consider these three only

By Hemant N Yadav
Example of State management
• Shopping cart
– Users Login information
• Username
• Cart Information
– These information are maintained between each
http request (any click by user for next page is
called http request).
• This can be done by any of the three methods
of state management.
By Hemant N Yadav
State management in PHP using
Cookie
• In PHP
– set_cookie(“name”,”value”,timeToExpires) method
is used to store information at client temporary
file.
– $_cookie[‘cookieName’]; is a super global variable
to access cookie information in page request.
– set_cookie(“name”,”value”,timeToExpires) if
timeToExpires is 0 cookie will be deleted.

By Hemant N Yadav
State management in PHP using
Session
• In PHP
– session_start() method is used to start session(or
say to create session variable internally)
– $_SESSION[‘key’] is used to set or get data of
session specified by key.
• Ex:
– Set Session data: <?PHP $_SESSION[‘uname’] =“myName”; ?>
– Get Session Data:<?PHP echo $_SESSION[‘uname’]; ?>
– unset($_SESSION[‘uname’]) for deleting session
variable key

By Hemant N Yadav
State management in PHP using
URL Re-writing/ Query String
• In PHP
– We can access data from Query String using
• $_GET[‘QueryStringVariableName’]
– We can append information in query string While
redirecting users using header function
• header(“Location: url?QueryStringVar=Val&…”);
• Disadvantages
– Limited data
– Security of Sensitive information
By Hemant N Yadav

You might also like