SlideShare a Scribd company logo
UNIT - 5
WEB APPLICATION, COOKIES AND SESSIONS
Sending email
• Syntax: mail(to, subject, body, [headers]);
• Eg:
$to = 'email@example.com';
$subject = 'This is the subject';
$body = 'This is the body. It goes over multiple lines.';
mail ($to, $subject, $body);
• Subject line cannot include ‘n’.
• Body should not exceed 70 characters.
$body = wordwrap($body, 70);
Example
Handling file uploads
• Steps
• Things to be considered:
• PHP- correct settings
• Temporary storage directory
• Final storage directory
• Allowing for file uploads:
php.ini
• Uploading files with PHP:
<form enctype="multipart/form-data" action="script.php"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
File <input type="file" name= "upload" />
• $_FILES: name, type, size, tmp_name, error.
• move_uploaded_file (temporary
_filename,/path/to/destination/filename);
Example
PHP and Javascript
• Javascript with HTML code can be done in 2 ways:
• Inline
• External file
• Inline Javascript
<script type="text/javascript">
// A c t u a l J a v a S c r i p t c o d e.
</script>
• External Javascript
<script type="text/javascript" src="somefile.js"></script>
Comparison
JAVASCRIPT PHP
Client side program Server side program
Can detect the size of popup, browser window and
image mouse over
Cannot detect
Cannot interact with MySQL Can interact with MySQL
Cannot generate PHP code Can dynamically generate Javascript
.js .php
OOP approach Procedural and OOP approach
In HTML: <script type=“text/javascript”>
</script>
<?php
?>
Understanding HTTP headers
• the uploaded images are being stored in the ‘uploads’ directory.
• the images cannot be viewed directly in the Web browser using either
of the following:
http://www.example.com/uploads/ image.png or
<img src="image.png" />
• create a proxy script in PHP.
http://www.example.com/proxy.php? image=image.png
or
<img src="proxy.php?image=image.png" />
Proxy script
Header()
• used to redirect the Web browser from the current page to another.
• syntax: header(header string);
• header ('Location: http://www.example.com/page.php’);
• To send a file:
header("Content-Type:application/pdfn");
header ("Content-Disposition: attachment;
filename="somefile.pdf"n");
header ("Content-Length: 4096n");
Date and time function
• Date_default_timezone_set(tz);
• Checkdate();
• Date(format, [timestamp]);
Date() function
formatting
• Eg:
echo date('F j, Y'); // January 26, 2011
echo date('H:i'); // 23:14
echo date('D'); // Sat
• mktime(): mktime (hour, minute, second, month, day, year);
• getdate():
$today = getdate( );
echo $today['month']; // October
getdate() array
Making a Login page
Making the login functions
• header ('Location: http://www. example.com/page.php');
exit( );
• 3 step process:
• Email address
• Password
• Email address and password
Using cookies
• a way for a server to store information on the user’s machine.
Setting cookies
• Setcookie(name, value, expiration, path, host, secure, httponly);
Accessing cookies
Deleting cookies
Session
• Data stored on the server.
• Advantages of session over cookies:
• Secure
• More data
• Without cookies
• Advantages of cookies over session:
• Easier
• Less of server
• More time
Setting the session
• Session_start()
• Accessing the session: $_SESSION
• Deleting the session:
• Unset($_SESSION[‘var’]);
• $_SESSION=array();
• Session_destroy();
Improving session security
• Session ID and session data
• HTTP_USER_AGENT
$_SESSION[‘agent’]=md5($_SERVER[‘HTTP_USER_AGENT’]);

More Related Content

What's hot (17)

KEY
MongoDB at RubyEnRails 2009
Mike Dirolf
 
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Brian Hogg
 
PPT
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
ryanduff
 
KEY
Extending Custom Post Types
ryanduff
 
PPTX
Amp and higher computing science
Charlie Love
 
PDF
4Developers: Michał Papis- Publikowanie gemów
PROIDEA
 
PDF
Php converted pdf
Northpole Web Service
 
PDF
Webinar: Getting Started with Ruby and MongoDB
MongoDB
 
PDF
Getting Started with WP-CLI, a tool to automate your life
AJ Morris
 
PDF
Modern Perl Web Development with Dancer
Dave Cross
 
ODP
Php File Upload
Hiroaki Kawai
 
PPTX
Type URL, Enter, and Then …
Jinglun Li
 
PPTX
php (Hypertext Preprocessor)
Chandan Das
 
KEY
Express Presentation
aaronheckmann
 
PDF
CouchDB for Web Applications - Erlang Factory London 2009
Jason Davies
 
PDF
Nanoc
joren de groof
 
MongoDB at RubyEnRails 2009
Mike Dirolf
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Brian Hogg
 
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
ryanduff
 
Extending Custom Post Types
ryanduff
 
Amp and higher computing science
Charlie Love
 
4Developers: Michał Papis- Publikowanie gemów
PROIDEA
 
Php converted pdf
Northpole Web Service
 
Webinar: Getting Started with Ruby and MongoDB
MongoDB
 
Getting Started with WP-CLI, a tool to automate your life
AJ Morris
 
Modern Perl Web Development with Dancer
Dave Cross
 
Php File Upload
Hiroaki Kawai
 
Type URL, Enter, and Then …
Jinglun Li
 
php (Hypertext Preprocessor)
Chandan Das
 
Express Presentation
aaronheckmann
 
CouchDB for Web Applications - Erlang Factory London 2009
Jason Davies
 

Similar to Web application, cookies and sessions (20)

PPTX
PHP 2
Richa Goel
 
PDF
PHP Web Development
gaplabs
 
PDF
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Common Gateway Interface
Balu Masulkar
 
PDF
4.4 PHP Session
Jalpesh Vasa
 
PDF
Tips
mclee
 
PDF
PHP Making Web Forms
krishnapriya Tadepalli
 
PPT
Chapter 08 php advance
Dhani Ahmad
 
ODP
PHP BASIC PRESENTATION
krutitrivedi
 
PPTX
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
PDF
Cgi
AkramWaseem
 
ODP
LAMP security practices
Amit Kejriwal
 
PPTX
BITM3730 10-25.pptx
MattMarino13
 
PPTX
BITM3730 10-24.pptx
MattMarino13
 
PDF
Intro to Php Security
Dave Ross
 
ODP
Ph
ksujitha
 
PDF
Configuring the Apache Web Server
webhostingguy
 
PHP 2
Richa Goel
 
PHP Web Development
gaplabs
 
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
Common Gateway Interface
Balu Masulkar
 
4.4 PHP Session
Jalpesh Vasa
 
Tips
mclee
 
PHP Making Web Forms
krishnapriya Tadepalli
 
Chapter 08 php advance
Dhani Ahmad
 
PHP BASIC PRESENTATION
krutitrivedi
 
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PHP Hypertext Preprocessor
adeel990
 
LAMP security practices
Amit Kejriwal
 
BITM3730 10-25.pptx
MattMarino13
 
BITM3730 10-24.pptx
MattMarino13
 
Intro to Php Security
Dave Ross
 
Configuring the Apache Web Server
webhostingguy
 
Ad

More from hamsa nandhini (19)

PPTX
SOA - Unit 5 - SOA and Business Process Management
hamsa nandhini
 
PPTX
SOA - Unit 4 - SOA & Web Services for integration and Multi-Channel access
hamsa nandhini
 
PPTX
SOA - Unit 3 - SOA and Web Services
hamsa nandhini
 
PPTX
SOA - Unit 2 - Service Oriented Architecture
hamsa nandhini
 
PPTX
SOA - Unit 1 - Introduction to SOA with Web Services
hamsa nandhini
 
PPTX
NP - Unit 5 - Bootstrap, Autoconfigurion and BGP
hamsa nandhini
 
PPTX
NP - Unit 4 - Routing - RIP, OSPF and Internet Multicasting
hamsa nandhini
 
PPTX
NP - Unit 3 - Forwarding Datagram and ICMP
hamsa nandhini
 
PPTX
NP - Unit 2 - Internet Addressing, ARP and RARP
hamsa nandhini
 
PPTX
Unit 1
hamsa nandhini
 
PPTX
PHP with MySQL
hamsa nandhini
 
PPTX
Database design and error handling
hamsa nandhini
 
PPTX
Introduction to MySQL in PHP
hamsa nandhini
 
PPTX
Basics of PHP
hamsa nandhini
 
PPTX
XML Security
hamsa nandhini
 
PPTX
SOAP and Web services
hamsa nandhini
 
PPTX
XML Technologies
hamsa nandhini
 
PPTX
XML DTD and Schema
hamsa nandhini
 
PPTX
fundamentals of XML
hamsa nandhini
 
SOA - Unit 5 - SOA and Business Process Management
hamsa nandhini
 
SOA - Unit 4 - SOA & Web Services for integration and Multi-Channel access
hamsa nandhini
 
SOA - Unit 3 - SOA and Web Services
hamsa nandhini
 
SOA - Unit 2 - Service Oriented Architecture
hamsa nandhini
 
SOA - Unit 1 - Introduction to SOA with Web Services
hamsa nandhini
 
NP - Unit 5 - Bootstrap, Autoconfigurion and BGP
hamsa nandhini
 
NP - Unit 4 - Routing - RIP, OSPF and Internet Multicasting
hamsa nandhini
 
NP - Unit 3 - Forwarding Datagram and ICMP
hamsa nandhini
 
NP - Unit 2 - Internet Addressing, ARP and RARP
hamsa nandhini
 
PHP with MySQL
hamsa nandhini
 
Database design and error handling
hamsa nandhini
 
Introduction to MySQL in PHP
hamsa nandhini
 
Basics of PHP
hamsa nandhini
 
XML Security
hamsa nandhini
 
SOAP and Web services
hamsa nandhini
 
XML Technologies
hamsa nandhini
 
XML DTD and Schema
hamsa nandhini
 
fundamentals of XML
hamsa nandhini
 
Ad

Recently uploaded (20)

PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
UNIT 1 - INTRODUCTION TO AI and AI tools and basic concept
gokuld13012005
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
UNIT 1 - INTRODUCTION TO AI and AI tools and basic concept
gokuld13012005
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 

Web application, cookies and sessions

  • 1. UNIT - 5 WEB APPLICATION, COOKIES AND SESSIONS
  • 2. Sending email • Syntax: mail(to, subject, body, [headers]); • Eg: $to = '[email protected]'; $subject = 'This is the subject'; $body = 'This is the body. It goes over multiple lines.'; mail ($to, $subject, $body); • Subject line cannot include ‘n’. • Body should not exceed 70 characters. $body = wordwrap($body, 70);
  • 4. Handling file uploads • Steps • Things to be considered: • PHP- correct settings • Temporary storage directory • Final storage directory • Allowing for file uploads: php.ini
  • 5. • Uploading files with PHP: <form enctype="multipart/form-data" action="script.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> File <input type="file" name= "upload" /> • $_FILES: name, type, size, tmp_name, error. • move_uploaded_file (temporary _filename,/path/to/destination/filename);
  • 7. PHP and Javascript • Javascript with HTML code can be done in 2 ways: • Inline • External file • Inline Javascript <script type="text/javascript"> // A c t u a l J a v a S c r i p t c o d e. </script> • External Javascript <script type="text/javascript" src="somefile.js"></script>
  • 8. Comparison JAVASCRIPT PHP Client side program Server side program Can detect the size of popup, browser window and image mouse over Cannot detect Cannot interact with MySQL Can interact with MySQL Cannot generate PHP code Can dynamically generate Javascript .js .php OOP approach Procedural and OOP approach In HTML: <script type=“text/javascript”> </script> <?php ?>
  • 9. Understanding HTTP headers • the uploaded images are being stored in the ‘uploads’ directory. • the images cannot be viewed directly in the Web browser using either of the following: http://www.example.com/uploads/ image.png or <img src="image.png" /> • create a proxy script in PHP. http://www.example.com/proxy.php? image=image.png or <img src="proxy.php?image=image.png" />
  • 11. Header() • used to redirect the Web browser from the current page to another. • syntax: header(header string); • header ('Location: http://www.example.com/page.php’); • To send a file: header("Content-Type:application/pdfn"); header ("Content-Disposition: attachment; filename="somefile.pdf"n"); header ("Content-Length: 4096n");
  • 12. Date and time function • Date_default_timezone_set(tz); • Checkdate(); • Date(format, [timestamp]);
  • 14. • Eg: echo date('F j, Y'); // January 26, 2011 echo date('H:i'); // 23:14 echo date('D'); // Sat • mktime(): mktime (hour, minute, second, month, day, year); • getdate(): $today = getdate( ); echo $today['month']; // October
  • 17. Making the login functions • header ('Location: http://www. example.com/page.php'); exit( ); • 3 step process: • Email address • Password • Email address and password
  • 18. Using cookies • a way for a server to store information on the user’s machine.
  • 19. Setting cookies • Setcookie(name, value, expiration, path, host, secure, httponly);
  • 22. Session • Data stored on the server. • Advantages of session over cookies: • Secure • More data • Without cookies • Advantages of cookies over session: • Easier • Less of server • More time
  • 23. Setting the session • Session_start()
  • 24. • Accessing the session: $_SESSION • Deleting the session: • Unset($_SESSION[‘var’]); • $_SESSION=array(); • Session_destroy();
  • 25. Improving session security • Session ID and session data • HTTP_USER_AGENT $_SESSION[‘agent’]=md5($_SERVER[‘HTTP_USER_AGENT’]);