SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Introduction to PHP
Web programming
Week 11, day2
Web programming
PHP with HTML
‱ You can embed PHP code inside html:
<html>
<body>
<h1>
<?php
$str_one = "Helloo World!";
echo $str_one;
?>
</h1>
</body>
</html>
‱ Or you can call html from php:
<?php
echo "<html><body><h2>Helloo Baabtra</h2></body></html>”;
?>
Client - Server communication with Form Data
When you submit the form- all form element data(username and password ) will
be send to the file ‚registration.php‛ which is residing on your server
HTML Form Example
HTML Form Example
Action specifies where to send the form data? Normally we
specify a page which resides on server so that all form data will be
sent to that page. In this example when you click submit button
data you entered will be send to “registation.php”
HTML Form Example
We can send data to server in two ways
GET or POST.
Form action and methods
‱There are two methods that we can send form data from client to server
‱ GET
‱ Allows you to send data as part of the query string.That means data will
be appended with the url
‱http://example.org/index.php?list=user&orderby=name&direction=asc
‱ POST
Allows the client to send along a data payload, for example, if you are
posting an HTTP form, the payload could consist of the form data, while if
you are uploading a file, the payload would consist of the file itself. Payload
will be with HTTP request so that it will not be visible to the user
Comparison
‱ Data sent will be shown in the URL
‱ Size of Data can be send is limiter
normally ~2kb but its browser
dependant
‱ Cannot be used to send binary
data like image or document
‱ Bookmarking is possible with GET
method
‱ Data will not be shown with the browser
‱ No restrictions on size of data
‱ Can be used to send files
‱ Book marking is not possible with POST
method
GET POST
How will you get that data in ‚registration.php‛ ???
‱ All the form data sent via Get method will be stored in a super global Array
$_GET
‱ Eg: http://example.org/index.php?list=user&orderby=name&direction=asc
echo $_GET*’list’+;
‱ You can create arrays by using array notation...
Eg: http://example.org/index.php?list=user&order[by]=column&order[dir]=asc
‱and then access them using the following syntax:
echo $_GET*’order’+*’by’+;
echo $_GET*’order’+*’direction’+;
How will you get that data in ‚registration.php‛ ???
‱ Similarly all the form data sent via POST method will be stored in a super global
array $_POST
‱Eg:
echo $_POST*‘name’+; // will output baabtra
echo $_POST*‘email’+; // will output info@baabtra.com
When You Don’t Know How Data Is Sent
‱ If you want to receive data send by client browser but you don’t know the method
they used to send (GET or POST), you can do this by using $_REQUEST[] super
global array
‱ ie. $_REQUEST[] will contain what ever data you send in any method either GET
or POST.
‱ Eg: echo $_REQUEST*‘name’+;
Try this
‱ Create a HTML form as below . Try both Get and POST methods
‱ Up on clicking submit button it should display what user have
entered
localhost/test/Registration.php
Baabtra
info@baabtra.com
localhost/test/Registration.php
Managing File uploads
File Uploading
‱ File uploads are an important feature for many Web applications;
‱ A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
File Uploading
‱ File uploads are an important feature for many Web applications;
‱ A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
is an encoding type that allows files to be sent
through a POST. Quite simply, without this
encoding the files cannot be sent through POST.
File Uploading
‱ File uploads are an important feature for many Web applications;
‱ A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
MAX_FILE_SIZE value is used to define the
maximum file size allowed
(in this case, 50,000 bytes)
File Uploading
‱ File uploads are an important feature for many Web applications;
‱ A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
Tip :You can limit the amount of data uploaded by a POST operation
by modifying number of configuration directives in php.ini, such as
post_max_size, max_input_time and upload_max_filesize.
How will you receive the file at server side?
‱ Once a file is uploaded to the server, PHP stores it in a temporary location and
makes it available to the script; It is up to the script to move the file to a safe
location. The temporary copy is automatically destroyed when the script ends.
‱ Inside your script, uploaded files will appear in the $_FILES super global multi
dimensional array. This array will have the following keys
– name : The original name of the file
– type : The MIME type of the file provided by the browser
– size : The size (in bytes) of the file
– tmp_name : The name of the file’s temporary location
– error : The error code associated with this file. A value of
UPLOAD_ERR_OK indicates a successful transfer
Built in functions for file upload()
‱ is_uploaded_file(filename) : returns true if the file has uploaded to the
temporary location in server
‱ Accepts and argument ‚filename‛ which refers to the name of the file in servers
temporary position.ie it will be $_FILE*‘filename’+*‘tmp_name’+
‱ move_uploaded_file(source,destination) : to move an uploaded file to a
different location
‱ Source refers to its current location which obviously is in the temporary
location in the server ie $_FILE*‘filename’+*‘tmp_name’+
‱ Destination refers to where to move the file along with its name eg.
‚images/profilePics/‛. $_FILE*‘filename’+*‘name’+
form enctype="multipart/form-data" action=‚register.php‚ method="post">
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
Example – File Upload
Index.html
<?php
echo $_FILE*‘filedata’+*‘name’+; // prints the name of file uploaded
echo $_FILE*‘filedata’+*‘size’+; // prints the size of file uploaded
is_uploaded_file($_FILE*‘filedata’+*‘tmp_name’+)
{
$target=‚images/‛.$_FILE*‘filedata’+*‘name’+;
move_upload_file($_FILE*‘filedata’+*‘tmp_name’+,$target);
}
?>
Example – File Upload
Register.php
Questions?
‚A good question deserve a good grade
‛
End of day
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

Mais conteĂșdo relacionado

Mais procurados

PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSAminiel Michael
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to phpTaha Malampatti
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Web Development Course: PHP lecture 4
Web Development Course: PHP  lecture 4Web Development Course: PHP  lecture 4
Web Development Course: PHP lecture 4Gheyath M. Othman
 
Php Presentation
Php PresentationPhp Presentation
Php PresentationManish Bothra
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Gheyath M. Othman
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)Arjun Shanka
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQLTiji Thomas
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntaxDhani Ahmad
 
What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESIsmail Mukiibi
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to phpMeetendra Singh
 

Mais procurados (20)

PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Web Development Course: PHP lecture 4
Web Development Course: PHP  lecture 4Web Development Course: PHP  lecture 4
Web Development Course: PHP lecture 4
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
PHP Function
PHP Function PHP Function
PHP Function
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
php
phpphp
php
 
Php
PhpPhp
Php
 

Destaque

Php & mysql course syllabus
Php & mysql course syllabusPhp & mysql course syllabus
Php & mysql course syllabusPapitha Velumani
 
Php project training in ahmedabad
Php project training in ahmedabadPhp project training in ahmedabad
Php project training in ahmedabadDevelopers Academy
 
PHP Project development with Vagrant
PHP Project development with VagrantPHP Project development with Vagrant
PHP Project development with VagrantBahattin Çiniç
 
開構ç¶Č站蚭蚈
開構ç¶Čç«™èš­èšˆé–‹ć§‹ç¶Č站蚭蚈
開構ç¶Čç«™èš­èšˆèł‡ćœ„ è§Ł
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1Kanchilug
 
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdmin
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdminMySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdmin
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdminèł‡ćœ„ è§Ł
 
Intro to Web Design
Intro to Web DesignIntro to Web Design
Intro to Web DesignCassie McDaniel
 
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 ...èł‡ćœ„ è§Ł
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesTOPS Technologies
 
Intro to Web Design
Intro to Web DesignIntro to Web Design
Intro to Web DesignKathy Gill
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xamppJin Castor
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingNoel Malle
 

Destaque (20)

Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Php & mysql course syllabus
Php & mysql course syllabusPhp & mysql course syllabus
Php & mysql course syllabus
 
Php project training in ahmedabad
Php project training in ahmedabadPhp project training in ahmedabad
Php project training in ahmedabad
 
Html , php, mysql intro
Html , php, mysql introHtml , php, mysql intro
Html , php, mysql intro
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
PHP Project development with Vagrant
PHP Project development with VagrantPHP Project development with Vagrant
PHP Project development with Vagrant
 
開構ç¶Č站蚭蚈
開構ç¶Čç«™èš­èšˆé–‹ć§‹ç¶Č站蚭蚈
開構ç¶Č站蚭蚈
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
 
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdmin
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdminMySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdmin
MySQLèł‡æ–™ćș«èš­èšˆèŠćŠƒèˆ‡phpMyAdmin
 
Intro to Web Design
Intro to Web DesignIntro to Web Design
Intro to Web Design
 
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 ...
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training Guidelines
 
Intro to Web Design
Intro to Web DesignIntro to Web Design
Intro to Web Design
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xampp
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
MySQL
MySQLMySQL
MySQL
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 

Semelhante a Introduction to php web programming - get and post

PHP fundamnetal in information technology CHapter -02.pptx
PHP fundamnetal in information technology CHapter -02.pptxPHP fundamnetal in information technology CHapter -02.pptx
PHP fundamnetal in information technology CHapter -02.pptxworldchannel
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Mohd Harris Ahmad Jaal
 
Web application, cookies and sessions
Web application, cookies and sessionsWeb application, cookies and sessions
Web application, cookies and sessionshamsa nandhini
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Gheyath M. Othman
 
Chapter 6 Getting Data from the Client (1).pptx
Chapter 6 Getting Data from the Client (1).pptxChapter 6 Getting Data from the Client (1).pptx
Chapter 6 Getting Data from the Client (1).pptxAhmedKafi7
 
lecture 11.pptx
lecture 11.pptxlecture 11.pptx
lecture 11.pptxITNet
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload MysqlGeshan Manandhar
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erickokelloerick
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07Hassen Poreya
 
forms.pptx
forms.pptxforms.pptx
forms.pptxasmabagersh
 
Uploading a file with php
Uploading a file with phpUploading a file with php
Uploading a file with phpMuhamad Al Imran
 
Introduction to web development - HTML 5
Introduction to web development - HTML 5Introduction to web development - HTML 5
Introduction to web development - HTML 5Ayoub Ghozzi
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Subhasis Nayak
 

Semelhante a Introduction to php web programming - get and post (20)

PHP fundamnetal in information technology CHapter -02.pptx
PHP fundamnetal in information technology CHapter -02.pptxPHP fundamnetal in information technology CHapter -02.pptx
PHP fundamnetal in information technology CHapter -02.pptx
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
 
Web application, cookies and sessions
Web application, cookies and sessionsWeb application, cookies and sessions
Web application, cookies and sessions
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2
 
Chapter 6 Getting Data from the Client (1).pptx
Chapter 6 Getting Data from the Client (1).pptxChapter 6 Getting Data from the Client (1).pptx
Chapter 6 Getting Data from the Client (1).pptx
 
lecture 11.pptx
lecture 11.pptxlecture 11.pptx
lecture 11.pptx
 
Copy of cgi
Copy of cgiCopy of cgi
Copy of cgi
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload Mysql
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
 
forms.pptx
forms.pptxforms.pptx
forms.pptx
 
Creating forms
Creating formsCreating forms
Creating forms
 
Php advance
Php advancePhp advance
Php advance
 
Uploading a file with php
Uploading a file with phpUploading a file with php
Uploading a file with php
 
File Upload
File UploadFile Upload
File Upload
 
Introduction to web development - HTML 5
Introduction to web development - HTML 5Introduction to web development - HTML 5
Introduction to web development - HTML 5
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 

Mais de baabtra.com - No. 1 supplier of quality freshers

Mais 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 sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
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
 

Último

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Introduction to php web programming - get and post

  • 1. Introduction to PHP Web programming Week 11, day2
  • 3. PHP with HTML ‱ You can embed PHP code inside html: <html> <body> <h1> <?php $str_one = "Helloo World!"; echo $str_one; ?> </h1> </body> </html> ‱ Or you can call html from php: <?php echo "<html><body><h2>Helloo Baabtra</h2></body></html>”; ?>
  • 4. Client - Server communication with Form Data
  • 5. When you submit the form- all form element data(username and password ) will be send to the file ‚registration.php‛ which is residing on your server HTML Form Example
  • 6. HTML Form Example Action specifies where to send the form data? Normally we specify a page which resides on server so that all form data will be sent to that page. In this example when you click submit button data you entered will be send to “registation.php”
  • 7. HTML Form Example We can send data to server in two ways GET or POST.
  • 8. Form action and methods ‱There are two methods that we can send form data from client to server ‱ GET ‱ Allows you to send data as part of the query string.That means data will be appended with the url ‱http://example.org/index.php?list=user&orderby=name&direction=asc ‱ POST Allows the client to send along a data payload, for example, if you are posting an HTTP form, the payload could consist of the form data, while if you are uploading a file, the payload would consist of the file itself. Payload will be with HTTP request so that it will not be visible to the user
  • 9. Comparison ‱ Data sent will be shown in the URL ‱ Size of Data can be send is limiter normally ~2kb but its browser dependant ‱ Cannot be used to send binary data like image or document ‱ Bookmarking is possible with GET method ‱ Data will not be shown with the browser ‱ No restrictions on size of data ‱ Can be used to send files ‱ Book marking is not possible with POST method GET POST
  • 10. How will you get that data in ‚registration.php‛ ??? ‱ All the form data sent via Get method will be stored in a super global Array $_GET ‱ Eg: http://example.org/index.php?list=user&orderby=name&direction=asc echo $_GET*’list’+; ‱ You can create arrays by using array notation... Eg: http://example.org/index.php?list=user&order[by]=column&order[dir]=asc ‱and then access them using the following syntax: echo $_GET*’order’+*’by’+; echo $_GET*’order’+*’direction’+;
  • 11. How will you get that data in ‚registration.php‛ ??? ‱ Similarly all the form data sent via POST method will be stored in a super global array $_POST ‱Eg: echo $_POST*‘name’+; // will output baabtra echo $_POST*‘email’+; // will output info@baabtra.com
  • 12. When You Don’t Know How Data Is Sent ‱ If you want to receive data send by client browser but you don’t know the method they used to send (GET or POST), you can do this by using $_REQUEST[] super global array ‱ ie. $_REQUEST[] will contain what ever data you send in any method either GET or POST. ‱ Eg: echo $_REQUEST*‘name’+;
  • 13. Try this ‱ Create a HTML form as below . Try both Get and POST methods ‱ Up on clicking submit button it should display what user have entered localhost/test/Registration.php Baabtra info@baabtra.com localhost/test/Registration.php
  • 15. File Uploading ‱ File uploads are an important feature for many Web applications; ‱ A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form>
  • 16. File Uploading ‱ File uploads are an important feature for many Web applications; ‱ A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> is an encoding type that allows files to be sent through a POST. Quite simply, without this encoding the files cannot be sent through POST.
  • 17. File Uploading ‱ File uploads are an important feature for many Web applications; ‱ A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> MAX_FILE_SIZE value is used to define the maximum file size allowed (in this case, 50,000 bytes)
  • 18. File Uploading ‱ File uploads are an important feature for many Web applications; ‱ A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> Tip :You can limit the amount of data uploaded by a POST operation by modifying number of configuration directives in php.ini, such as post_max_size, max_input_time and upload_max_filesize.
  • 19. How will you receive the file at server side? ‱ Once a file is uploaded to the server, PHP stores it in a temporary location and makes it available to the script; It is up to the script to move the file to a safe location. The temporary copy is automatically destroyed when the script ends. ‱ Inside your script, uploaded files will appear in the $_FILES super global multi dimensional array. This array will have the following keys – name : The original name of the file – type : The MIME type of the file provided by the browser – size : The size (in bytes) of the file – tmp_name : The name of the file’s temporary location – error : The error code associated with this file. A value of UPLOAD_ERR_OK indicates a successful transfer
  • 20. Built in functions for file upload() ‱ is_uploaded_file(filename) : returns true if the file has uploaded to the temporary location in server ‱ Accepts and argument ‚filename‛ which refers to the name of the file in servers temporary position.ie it will be $_FILE*‘filename’+*‘tmp_name’+ ‱ move_uploaded_file(source,destination) : to move an uploaded file to a different location ‱ Source refers to its current location which obviously is in the temporary location in the server ie $_FILE*‘filename’+*‘tmp_name’+ ‱ Destination refers to where to move the file along with its name eg. ‚images/profilePics/‛. $_FILE*‘filename’+*‘name’+
  • 21. form enctype="multipart/form-data" action=‚register.php‚ method="post"> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> Example – File Upload Index.html
  • 22. <?php echo $_FILE*‘filedata’+*‘name’+; // prints the name of file uploaded echo $_FILE*‘filedata’+*‘size’+; // prints the size of file uploaded is_uploaded_file($_FILE*‘filedata’+*‘tmp_name’+) { $target=‚images/‛.$_FILE*‘filedata’+*‘name’+; move_upload_file($_FILE*‘filedata’+*‘tmp_name’+,$target); } ?> Example – File Upload Register.php
  • 23. Questions? ‚A good question deserve a good grade
‛
  • 25. 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