Receiving form Variables

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
1 Controlling Script Flow! David Lash Chapter 3 Conditional Statements.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Python and Web Programming
1 PHP and MySQL David Lash Module 2 Working with forms, PHP conditionals and loops.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Unit 7 – Working with Forms 1. Creating a form 2. Accessing the submitted data 3. Common operations on forms.
9/4/2015CS346 PHP1 CHAPTER 2 Using Variables. 9/4/2015CS346 PHP2 Objectives  How to store and access data in PHP variables  How to create and manipulate.
PHP Security.
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.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
A little PHP. Enter the simple HTML code seen below.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
Slide 7-1 CHAPTER 7 Managing Multiple-Form Applications: Writing scripts with multiple screens.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Slide 2-1 The Web Wizard’s Guide to PHP by David A. Lash.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
Slide 3-1 CHAPTER 3 Conditional Statements Objectives To learn to use conditional test statements to compare numerical and string data values To learn.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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.
1 Module 3 Conditional Statements. Objectives  Conditional test statements to compare numerical and string data values  Looping statements to repeat.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Form Handling IDIA 618 Fall 2014 Bridget M. Blodgett.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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 Web Wizards Guide To PHP David Lash Chapter 2 Using Variables.
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.
PHP Security: register_globals How To Make It Difficult For Hackers To Set Variables.
NMD202 Web Scripting Week2. Web site
Copyright © 2003 Pearson Education, Inc. Slide 2-1 The Web Wizard’s Guide to PHP by David A. Lash.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 The Web Wizard’s Guide to PHP by David A. Lash.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
Radoslav Georgiev Telerik Corporation
Web Programming with PHP (3) Superglobals, Form & File processing.
Simple PHP Web Applications Server Environment
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Web Database Programming Using PHP
CGS 3066: Web Programming and Design Spring 2017
A little PHP.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Example – SQL Injection
Web Database Programming Using PHP
DBW - PHP DBW2017.
Web Technologies PHP 5 Basic Language.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Passing variables between pages
PHP FORM HANDLING Post Method
HTML Forms and User Input
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
Web Development & Design Foundations with H T M L 5
The Web Wizard’s Guide to PHP
Web Development & Design Foundations with H T M L 5
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
PHP PART 2.
PHP an introduction.
The Web Wizard’s Guide to PHP by David A. Lash
PHP-II.
Presentation transcript:

Receiving form Variables Module 2B Receiving form Variables

Register_Globals? Since PHP 4.2.1, the default PHP configuration requires a different mechanism to receive input for security reasons (than the one just shown) PHP configuration option to turn REGISTER_GLOBALS OFF (new default) or ON in the php.ini configuration file. If your site has REGISTER_GLOBALS OFF you must use a different mechanism to receive HTML Form Variables.

How can you tell if Register_Globals is OFF? Enter the following PHP script and run it. <?PHP phpinfo(); ?> Use m06/6-8checkPHPini.php Search through the output for REGISTER_GLOBALS and see if it is set to OFF or ON. If it is off you may use the following ways to receive input data.

Effects of register_globals register_globals boolean Tells whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables. For example; if register_globals = on, the url http://www.example.com/test.php?id=3 will produce $id. Or, $DOCUMENT_ROOT from $_SERVER['DOCUMENT_ROOT']. User data may clutter your PHP globals and even become a security risk

Why REGISTER_GLOBALS OFF? Security <?php // define $authorized = true only if user is authenticated if (authenticated_user()) { $authorized = true; } /* Because we didn't first initialize $authorized as false, this might be defined through register_globals, like from GET auth.php?authorized=1 So, anyone can be seen as authenticated! */ if ($authorized) { include "/highly/sensitive/data.php"; } ?>

How do we get user variables? As of PHP 4.2.0, this directive defaults to off It's preferred to go through PHP Predefined Variables instead, such as the superglobals: $_ENV, $_GET, $_POST, $_COOKIE, and $_SERVER. Read the security chapter on Using register_globals for related information http://us3.php.net/import_request_variables http://us3.php.net/manual/en/language.variables.external.php

Getting input data with Register_Globals OFF? Method 1 To receive data with REGISTER_GLOBALS OFF you use a special variable called $_POST $name $_POST[‘name’]; Enclose in square bracket and quotes (see next slide) Name of HTML form variable (no $) PHP SuperGlobal. Technically it is an associative array PHP variable name that you want to receive the HTML form input.

Note on quotes around name Update on 11/12/2003 You may use single or double quotes around the name of html form variable. The following are both acceptable: $name = $_POST[‘name’]; $name = $_POST[“name”];

When REGISTER_GLOBALS is OFF Suppose your HTML form uses the following: Enter email address: <input type="text" size="16" maxlength="20" name="email"> Then can receive input as follows: 1. <html> 2. <head><title> Receiving Input </title> </head> 3. <body> 4. <?php $email = $_POST[‘email’]; // Note Single Quote 5. $contact = $_POST[‘contact’]; ?> 6. <h2>Thank You: Got Your Input.</h2> 7. <?php 8. print ("<br>Your email address is $email"); 9. print ("<br> Contact preference is $contact"); 10. ?>

A Full Example ... The previous code can be executed at http://localhost/m06/6-0form_global_off.htm and http://localhost/6-0form_global_off.php

Method 2: Recommended by php to handle GET/POST/Cookie variables into the global scope Use the function bool import_request_variables ( string types [, string prefix]) types parameter specifies which request variables to import 'G', 'P' and 'C' characters respectively for GET, POST and Cookie Order matters. If types ==“gp”, POST variables overwrite GET variables

Method 2: import_request_variables bool import_request_variables ( string types [, string prefix]) prefix parameter is used as a variable name prefix, prepended before all variable's name imported into the global scope So if you have a GET value named "userid", and provide a prefix "pref_", then you'll get a global variable named $pref_userid. Reference: http://us3.php.net/import_request_variables

<html> <head><title> Receiving Input </title> </head> <body> <font size=5>Thank You: Got Your Input.</font> <?php /* The following is recommended by php to handle GET/POST/Cookie variables into the global scope. Reference: http://us3.php.net/import_request_variables */ import_request_variables("gp", "form27_"); print ("<br>Your email address is $form27_email"); print ("<br> Contact preference is $form27_contact"); ?> </body> </html>

Full Example The previous code can be executed at http://localhost/m06/6-0form_2nd_global.htm and http://localhost/m06/6-0form_2nd_global.php

Third way If html form uses post Use in form.php Example: <form method = "post" action = "form.php"> Use in form.php extract( $_POST ); Example: Fig_23_12_13 of textbook

Summary PHP supports both numeric and string variables. String variables use different methods for value manipulation (for example, concatenation) than numeric variables do

Summary Use HTML forms to pass data to PHP scripts HTML form elements include text boxes, text areas, password boxes, check boxes, radio buttons, and selection lists. PHP scripts can receive form element input values by using a PHP variable name that matches the one specified in the form element’s name argument. If RESITER_GLOBALS is off in your installation you must get input data using $_POST[“var_name”];