SlideShare a Scribd company logo
1 of 10
Download to read offline
PHP Making Web
Forms
Krishna priya
April 20, 2011
C-DAC, Hyderabad
PHP GET and POST Methods
Before the browser sends the information, it encodes using a
scheme called URL encoding.
There are two ways the browser client can send information to the
web server.

The GET Method
The POST Method

The PHP $_GET and $_POST variables are
used to retrieve information from forms, like user input.
The GET Method
The GET method sends the encoded user information
appended to the page request. The page and the encoded
information are separated by the ? character.
http://www.test.com/index.htm?name1=value1&name2=v
alue2
The GET method is restricted to send upto 1024 characters
only.
Never use GET method if you have password or other
sensitive information to be sent to the server.
GET can't be used to send binary data, like images or word
documents, to the server.
The information is encoded as described in case of GET
method and put into a header called QUERY_STRING.
The POST Method
The POST method transfers information via HTTP headers.
The POST method does not have any restriction on data size to
be sent.
The POST method can be used to send ASCII as well as binary
data
The data sent by POST method goes through HTTP header so
security depends on HTTP protocol. By using Secure HTTP you can
make sure that your information is secure.
Differences
The main difference between GET and POST is how the form data is
passing. Both are used for passing form field values.
All the values which is submitted by the GET method will be appended to
the URL.
Where as POST method send the data with out appending the URL(hidden)
In GET Method we can bookmark the URLs where as in POST method its
not possible
In GET Method there is a limit for passing the data from one page to
another(ie 256 characters according to w3c standards)
But in POST we can send large amount of data
Compared to POST get is Faster
POST is more secure than get method
All the informations which is passed by GET method will be stored in
webserver(log file) but in POST we can not
Validating Form data
isset() determines whether a certain variable has already
been declared by PHP. It returns a boolean value true if
the variable has already been set, and false otherwise, or
if the variable is set to the value NULL.
Consider the following script:
1. if (isset($first_name)) {
2. print '$first_name is set';
3. }
This code snippet checks whether the variable
$first_name is defined. If $first_name is defined, isset()
returns true , which will display ' $first_name is set. ' If it
isn’t, no output is generated.
PHP Cookies

1.
2.
3.

Cookies are text files stored on the client computer and
they are kept of use tracking purpose. PHP transparently
supports HTTP cookies.
There are three steps involved in identifying returning
users:
Server script sends a set of cookies to the browser. For
example name, age, or identification number etc.
Browser stores this information on local machine for future
use.
When next time browser sends any request to web server
then it sends those cookies information to the server and
server uses that information to identify the user.
Cookies are usually set in an HTTP header. A PHP script
that sets a cookie might send headers that look something
like this:
setcookie(name, value, expire, path, domain,
security);
PHP Cookies
Name - This sets the name of the cookie and is stored in an environment
variable called HTTP_COOKIE_VARS. This variable is used while accessing
cookies.
Value -This sets the value of the named variable and is the content that
you actually want to store.
Expiry - This specify a future time in seconds since 00:00:00 GMT on 1st
Jan 1970. After this time cookie will become inaccessible. If this parameter
is not set then cookie will automatically expire when the Web Browser is
closed.
Path -This specifies the directories for which the cookie is valid. A single
forward slash character permits the cookie to be valid for all directories.
Domain - This can be used to specify the domain name in very large
domains and must contain at least two periods to be valid. All cookies are
only valid for the host and domain which created them.
Security - This can be set to 1 to specify that the cookie should only be
sent by secure transmission using HTTPS otherwise set to 0 which mean
cookie can be OK Date: Tue, 19 Apr
HTTP/1.1 200sent by regular HTTP. 2011 21:03:38 GMT

Server: Apache/1.3.9 (UNIX) PHP/4.0b3
Set-Cookie: name=xyz; expires=Friday, 22-Apr-11 22:03:38
GMT; path=/; domain=Yourdomian.com
Connection: close Content-Type: text/html
PHP Sessions
An alternative way to make data accessible across the
various pages of an entire website is to use a PHP Session.
PHP has a great set of functions that can achieve the same
results of Cookies and more without storing information on
the user's computer. PHP Sessions store the information on
the web server in a location that you chose in special files.
These files are connected to the user's web browser via the
server and a special ID called a "Session ID". This is nearly
99% flawless in operation and it is virtually invisible to the
user.
The location of the temporary file is determined by a
setting in the php.ini file called session.save_path. Bore
using any session variable make sure you have setup this
path.
Avoid Error PHP - Sessions
PHP Example: <?php
echo "Look at this nasty error below:<br />";
session_start();
?>
Error!
Warning: Cannot send session cookie - headers
already sent by (output started at
session_header_error/session_error.php:2) in
session_header_error/session_error.php on line 3
Warning: Cannot send session cache limiter headers already sent (output started at
session_header_error/session_error.php:2) in
session_header_error/session_error.php on line 3

PHP Example: <?php
session_start();
echo "Look at this nasty error
below:";
?>
Correct

More Related Content

What's hot (20)

HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
html forms
html formshtml forms
html forms
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
2. HTML forms
2. HTML forms2. HTML forms
2. HTML forms
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
 
Html form tag
Html form tagHtml form tag
Html form tag
 
Web forms and html lecture Number 4
Web forms and html lecture Number 4Web forms and html lecture Number 4
Web forms and html lecture Number 4
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5
 
Forms in html5
Forms in html5Forms in html5
Forms in html5
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
Forms with html5 (1)
Forms with html5 (1)Forms with html5 (1)
Forms with html5 (1)
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attribute
 
Web design - Working with forms in HTML
Web design - Working with forms in HTMLWeb design - Working with forms in HTML
Web design - Working with forms in HTML
 
Html forms
Html formsHtml forms
Html forms
 
Html forms
Html formsHtml forms
Html forms
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Html forms
Html formsHtml forms
Html forms
 
Html forms
Html formsHtml forms
Html forms
 

Similar to PHP Making Web Forms

Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxShitalGhotekar
 
Common Gateway Interface
Common Gateway InterfaceCommon Gateway Interface
Common Gateway InterfaceBalu Masulkar
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfHumphreyOwuor1
 
Get and post methods in php - phpgurukul
Get and post methods in php  - phpgurukulGet and post methods in php  - phpgurukul
Get and post methods in php - phpgurukulPHPGurukul Blog
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Hassen Poreya
 
Form handling in php
Form handling in phpForm handling in php
Form handling in phpFahad Khan
 
The constrained application protocol (coap) part 2
The constrained application protocol (coap)  part 2The constrained application protocol (coap)  part 2
The constrained application protocol (coap) part 2Hamdamboy
 
The constrained application protocol (co ap) part 2
The constrained application protocol (co ap)  part 2The constrained application protocol (co ap)  part 2
The constrained application protocol (co ap) part 2Hamdamboy (함담보이)
 
The constrained application protocol (coap) part 2
The constrained application protocol (coap)  part 2The constrained application protocol (coap)  part 2
The constrained application protocol (coap) part 2Hamdamboy (함담보이)
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the WebTrevor Lohrbeer
 

Similar to PHP Making Web Forms (20)

Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptx
 
Common Gateway Interface
Common Gateway InterfaceCommon Gateway Interface
Common Gateway Interface
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
Get and post methods in php - phpgurukul
Get and post methods in php  - phpgurukulGet and post methods in php  - phpgurukul
Get and post methods in php - phpgurukul
 
Study of http
Study of httpStudy of http
Study of http
 
Http methods
Http methodsHttp methods
Http methods
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Form handling in php
Form handling in phpForm handling in php
Form handling in php
 
The constrained application protocol (coap) part 2
The constrained application protocol (coap)  part 2The constrained application protocol (coap)  part 2
The constrained application protocol (coap) part 2
 
The constrained application protocol (co ap) part 2
The constrained application protocol (co ap)  part 2The constrained application protocol (co ap)  part 2
The constrained application protocol (co ap) part 2
 
The constrained application protocol (coap) part 2
The constrained application protocol (coap)  part 2The constrained application protocol (coap)  part 2
The constrained application protocol (coap) part 2
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
Session and cookies ,get and post methods
Session and cookies ,get and post methodsSession and cookies ,get and post methods
Session and cookies ,get and post methods
 
HTTP Basics
HTTP BasicsHTTP Basics
HTTP Basics
 
www and http services
www and http serviceswww and http services
www and http services
 
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
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
 
Androidphpmysql
AndroidphpmysqlAndroidphpmysql
Androidphpmysql
 
forms.pptx
forms.pptxforms.pptx
forms.pptx
 

More from krishnapriya Tadepalli (13)

Web content accessibility
Web content accessibilityWeb content accessibility
Web content accessibility
 
Data visualization tools
Data visualization toolsData visualization tools
Data visualization tools
 
Drupal vs sitecore comparisons
Drupal vs sitecore comparisonsDrupal vs sitecore comparisons
Drupal vs sitecore comparisons
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management Systems
 
My sql vs mongo
My sql vs mongoMy sql vs mongo
My sql vs mongo
 
Node.js
Node.jsNode.js
Node.js
 
Json
JsonJson
Json
 
Comparisons Wiki vs CMS
Comparisons Wiki vs CMSComparisons Wiki vs CMS
Comparisons Wiki vs CMS
 
Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Using advanced features in joomla
Using advanced features in joomlaUsing advanced features in joomla
Using advanced features in joomla
 
Presentation joomla-introduction
Presentation joomla-introductionPresentation joomla-introduction
Presentation joomla-introduction
 
Language enabling
Language enablingLanguage enabling
Language enabling
 

Recently uploaded

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

PHP Making Web Forms

  • 1. PHP Making Web Forms Krishna priya April 20, 2011 C-DAC, Hyderabad
  • 2. PHP GET and POST Methods Before the browser sends the information, it encodes using a scheme called URL encoding. There are two ways the browser client can send information to the web server. The GET Method The POST Method The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
  • 3. The GET Method The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character. http://www.test.com/index.htm?name1=value1&name2=v alue2 The GET method is restricted to send upto 1024 characters only. Never use GET method if you have password or other sensitive information to be sent to the server. GET can't be used to send binary data, like images or word documents, to the server. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.
  • 4. The POST Method The POST method transfers information via HTTP headers. The POST method does not have any restriction on data size to be sent. The POST method can be used to send ASCII as well as binary data The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.
  • 5. Differences The main difference between GET and POST is how the form data is passing. Both are used for passing form field values. All the values which is submitted by the GET method will be appended to the URL. Where as POST method send the data with out appending the URL(hidden) In GET Method we can bookmark the URLs where as in POST method its not possible In GET Method there is a limit for passing the data from one page to another(ie 256 characters according to w3c standards) But in POST we can send large amount of data Compared to POST get is Faster POST is more secure than get method All the informations which is passed by GET method will be stored in webserver(log file) but in POST we can not
  • 6. Validating Form data isset() determines whether a certain variable has already been declared by PHP. It returns a boolean value true if the variable has already been set, and false otherwise, or if the variable is set to the value NULL. Consider the following script: 1. if (isset($first_name)) { 2. print '$first_name is set'; 3. } This code snippet checks whether the variable $first_name is defined. If $first_name is defined, isset() returns true , which will display ' $first_name is set. ' If it isn’t, no output is generated.
  • 7. PHP Cookies 1. 2. 3. Cookies are text files stored on the client computer and they are kept of use tracking purpose. PHP transparently supports HTTP cookies. There are three steps involved in identifying returning users: Server script sends a set of cookies to the browser. For example name, age, or identification number etc. Browser stores this information on local machine for future use. When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user. Cookies are usually set in an HTTP header. A PHP script that sets a cookie might send headers that look something like this: setcookie(name, value, expire, path, domain, security);
  • 8. PHP Cookies Name - This sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS. This variable is used while accessing cookies. Value -This sets the value of the named variable and is the content that you actually want to store. Expiry - This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed. Path -This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories. Domain - This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them. Security - This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be OK Date: Tue, 19 Apr HTTP/1.1 200sent by regular HTTP. 2011 21:03:38 GMT Server: Apache/1.3.9 (UNIX) PHP/4.0b3 Set-Cookie: name=xyz; expires=Friday, 22-Apr-11 22:03:38 GMT; path=/; domain=Yourdomian.com Connection: close Content-Type: text/html
  • 9. PHP Sessions An alternative way to make data accessible across the various pages of an entire website is to use a PHP Session. PHP has a great set of functions that can achieve the same results of Cookies and more without storing information on the user's computer. PHP Sessions store the information on the web server in a location that you chose in special files. These files are connected to the user's web browser via the server and a special ID called a "Session ID". This is nearly 99% flawless in operation and it is virtually invisible to the user. The location of the temporary file is determined by a setting in the php.ini file called session.save_path. Bore using any session variable make sure you have setup this path.
  • 10. Avoid Error PHP - Sessions PHP Example: <?php echo "Look at this nasty error below:<br />"; session_start(); ?> Error! Warning: Cannot send session cookie - headers already sent by (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3 Warning: Cannot send session cache limiter headers already sent (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3 PHP Example: <?php session_start(); echo "Look at this nasty error below:"; ?> Correct