PHP and Form Processing CS3520. Idea We have an HTML form that when user clicks on it in their browser a CGI HTTP request is created by the browser and.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Slide 1 of 40 PHP Form Handling The PHP superglobals $_GET and $_POST are used to collect form-data. EX: Name: CENG 449 Lecture 11.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Using Entities & Creating Forms Jill R. Sommer Institute for Applied Linguistics Kent State University.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
PHP Forms. I. Using PHP with HTML Forms A very common application of PHP is to have an HTML form gather information from a website's visitor and then.
Forms. Form An HTML form is a section of a document containing normal content, special elements called controls (checkboxes, radio buttons, buttons, etc.),
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
Unit 7 – Working with Forms 1. Creating a form 2. Accessing the submitted data 3. Common operations on forms.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Dr. Mogeeb A. A. Mosleh .
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
PHP : Hypertext Preprocessor
Week 4  Using PHP with HTML forms  Form Validation  Create your own Contact form Please Visit:
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
HTML Forms What is a form.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKPRO GUIDE Chapter 2: Programming with PHP Copyright © 2012 by Larry Ullman Dr. Mogeeb Mosleh Saturday ( pm)
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Week 7. Lecture 3 PHP Forms. PHP forms In part 2 of this course, we discussed html forms, php form is similar. Lets do a quick recap of the things we.
Slide 1 of 40 PHP Form Handling The PHP superglobals $_GET and $_POST are used to collect form-data. EX: Name: CENG 449 Lecture 11.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Website Development with PHP and MySQL Saving Data.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope.
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Part 2 Lecture 9 PHP Superglobals and Form Handling.
Web Technologies Lecture 3 Web forms. HTML5 forms A component of a webpage that has form controls – Text fields – Buttons – Checkboxes – Range controls.
CHAPTER 7 Introduction to PHP5 Part II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Working with Forms in PHP HTTP GET / POST, Validation, Escaping, Input Types, Submitting Arrays, URL Redirecting, PHP Superglobals Svetlin Nakov Technical.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Basic Webpage Design HTML Forms. Objectives Learn how to use HTML to create a form. Explain the concept of forms Know the difference of GET and POST Discuss.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Informatics Computer School CS114 Web Publishing HTML Lesson 4.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Simple PHP Web Applications Server Environment
Web Systems & Technologies
CSCE 548 Student Presentation Ryan Labrador
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
© Hugh McCabe 2000 Web Authoring Lecture 8
PHP Forms and Databases.
Presentation transcript:

PHP and Form Processing CS3520

Idea We have an HTML form that when user clicks on it in their browser a CGI HTTP request is created by the browser and sent to the server in the URL of the action statement of the form for processing --- Server o e.g. Apache gets request for a PHP file to run and then it knows where its PHP interpreter is and runs the code and Returns the results to the requesting Client /~netid/cart.php puzzle.sci.csueastbay.edupuzzle.sci.csueastbay.edu Server, Asking it to run cart.php

Recall In this class we are considering sending data from a client (like from a form) via either CGI GET or POST methods!!!

Slide 4 of 40 PHP Form Handling The PHP superglobals $_GET and $_POST are used to collect form-data. Example where we send to welcome.php the name and from a POST form. Name:

Slide 5 of 40 <?php $name=$_POST["name"]; //retrieve the CGI data associated with name $ =$_POST[" "]; //retrieve the CGI data associated with echo "Your name is ".$name." "; echo "Your is ".$ ." "; ?> welcome.php What client Sees: Your name is Lynne Your is User types into the form Name: Lynne

Slide 6 of 40 <?php if(isset($_POST["name"]) && isset($_POST[" "]) { $name=$_POST["name"]; $ =$_POST[" "]; echo "Your name is ".$name." "; echo "Your is ".$ ." "; } ?> welcome.php Check first to see if the data exists in the _POST array

Slide 7 of 40 Name: GET method example

Slide 8 of 40 <?php $name= $_GET ["name"]; $ = $_GET [" "]; echo "Your name is ".$name." "; echo "Your is ".$ ." "; ?>

Another Example – with pull down (select) lists

Slide 10 of 40 CENG 449 Lecture 11

Slide 11 of 40 Select Forms: Art Supply Order Form Paint Brushes Erasers Quantity:

Slide 12 of 40 process.php "; echo "Thank you for ordering!"; ?>

Slide 13 of 40 CENG 449 Lecture 11

Another Example- with radio buttons

Slide 15 of 40

Slide 16 of 40 PHP HTML Form radio button Example Enter Your Full Name : You are : Male Female

Slide 17 of 40 example.php <?php if(isset($_POST['BtnSubmit'])) { echo " Your form data as bellow "; echo " Your Name: {$_POST['FullName']}"; echo " Your are: {$_POST['YourGender']}"; echo " "; } ?>

Slide 18 of 40

Another example with checkboxes

Slide 20 of 40

Slide 21 of 40 Checkbox example: PHP HTML Form checkbox Example Male Female

Slide 22 of 40 process.php <?php if (isset($_POST['gender'])) { echo "Your gender is "; echo $_POST['gender']; // Displays value of checked checkbox. } ?>

Slide 23 of 40

More Examples –with buttons

Slide 25 of 40

Slide 26 of 40 PHP HTML Form button Example Enter Your Name : Enter Your SurName :

Slide 27 of 40 process.php <?php if (isset($_POST['save'])) { echo "Save button is pressed! "; } if (isset($_POST['clear'])) { echo "Clear button is pressed! "; } if (isset($_POST['update'])) { echo "Update button is pressed! "; } ?>

Slide 28 of 40

Example with checkboxes

Slide 30 of 40

Slide 31 of 40 Mulltiple Selection CheckBox: Please select your book types: Drama Action and Adventure Romance Mystery Horror Guide Science History

Slide 32 of 40 <?php $bookArray=$_POST['book']; echo "Your selected books are "; foreach ($bookArray as $aBook) { echo "$aBook "; } ?>

Slide 33 of 40

Security???

Security Option1: Some SIMPLE things to do with PHP Option2: Use SSL and HTTPS

Option1: Some special ideas Simple ideas to avoid SOME hacking/attacks possible with forms.

Slide 37 of 40 Secure input data To prevent hackers entering your system, use the following approach while inputting the data from user --- strip any incoming CGI data of spaces, etc…see below <?php // define variables and set to empty values $name = $ = $gender = $comment = $website = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = test_input($_POST["name"]); $ = test_input($_POST[" "]); $website = test_input($_POST["website"]); $comment = test_input($_POST["comment"]); $gender = test_input($_POST["gender"]); } function test_input($data) { $data = trim($data); // avoids the blank spaces at the beginning and at the end $data = stripslashes($data); // stripes slashes $data = htmlspecialchars($data); // convers special characters such as &lt return $data; } ?>

Slide 38 of 40 What is the htmlspecialchars() function? The htmlspecialchars() function converts special characters to HTML entities. This means that it will replace HTML characters like with < and >. This prevents attackers from exploiting the code by injecting HTML or Javascript code (Cross-site Scripting attacks) in forms. See: p p for an example

Slide 39 of 40 "> First name: Last name: <?php if(isset($_POST['firstname']) && isset($_POST['lastname'])) { echo("First name: ". $_POST['firstname']. " \n"); echo("Last name: ". $_POST['lastname']. " \n"); } ?> SILLY code that displays the form and then the data afterwards as text that was previously typed in --- shows using the htmlspecialchars function NOTE: $_SERVER[“PHP_SELF”] Is equal to the php you are currently processing, code you are in

Slide 40 of 40

Slide 41 of 40 \n" ); echo ( "Last name: ". $_POST[ 'lastname' ]. " \n"); } ?> "> First name: Last name: