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 E-mail.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
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.
Tutorial 14 Working with Forms and Regular Expressions.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(26) PHP (Personal Home Page)
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
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
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
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.
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)
Chapter 4: Basics of PHP 42. Topics Introduction Creating and Executing PHP Programs Variables Operators Constant Arrays String Processing and Regular.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
Chap 3: Web Programming (CCSB144) - PHP 42 Chapter 4 - PHP Outline Introduction PHP String Processing and Regular Expressions Viewing Client/Server Environment.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Tutorial 14 Working with Forms and Regular Expressions.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
CSCI 6962: Server-side Design and Programming Secure Web Programming.
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.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
JavaScript, Fourth Edition
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.
Creating a Web Site to Gather Data and Conduct Research.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
 2003 Prentice Hall, Inc. All rights reserved. 1 PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4 Viewing Client/Server.
Chapter 8 Cookies And Security JavaScript, Third Edition.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
Website Development with PHP and MySQL Saving Data.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Part 2 Lecture 9 PHP Superglobals and Form Handling.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
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.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
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 ©
PHP PART 2.
PHP Forms and Databases.
PHP-II.
Presentation transcript:

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 Lab Room : MM lab Tuesday ( am)

Client/Server Environment Variables Environment variables –Provide information about execution environment Type of Web browser Type of server Details of HTTP connection –Stored as array in PHP $_ENV

PhP Form Handling Form processing –action property Where to send form data (In/Out) –method property The PHP superglobals $_GET and $_POST are used to collect form-data. Each element has unique name

Example PhP Form Handling

GET vs. POST –Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3,...)). –This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user. –Both GET and POST are treated as $_GET and $_POST. –These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. –$_GET is an array of variables passed to the current script via the URL parameters. –$_POST is an array of variables passed to the current script via the HTTP POST method

PhP Form Handling When use GET –Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). –GET also has limits on the amount of information to send (2000 characters). –GET may be used for sending non-sensitive data. When use POST –Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request). –has no limits on the amount of information to send. –Developers prefer POST for sending form data.

PHP Form Validation Proper validation of form data is important to protect your form from hackers and spammers. Check the input data weather user appropriate data or not. $_SERVER["PHP_SELF"] –The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script. –$_SERVER["PHP_SELF"] sends the submitted form data to the page itself, instead of jumping to a different page. The htmlspecialchars() –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. Big Note on PHP Form Security –The $_SERVER["PHP_SELF"] variable can be used by hackers! –If PHP_SELF is used in your page then a user can enter a slash (/) and then some Cross Site Scripting (XSS) commands to execute.

PHP Form Validation How To Avoid $_SERVER["PHP_SELF"] Exploits? $_SERVER["PHP_SELF"] exploits can be avoided by using the htmlspecialchars() function. "> Validate Form Data With PHP  The first thing we will do is to pass all variables through PHP's htmlspecialchars() function.  Strip unnecessary characters (extra space, tab, newline) from the user input data (with the PHP trim() function)  Remove backslashes (\) from the user input data (with the PHP stripslashes() function)  The next step is to create a function that will do all the checking for us.

PHP Form Validation Example: ">

PHP Forms - Required Fields

11 form.html (1 of 4) The action attribute of the form element indicates that when the user clicks Register, the form data will be posted to form.php.

12 form.html (2 of 4) A unique name (e.g., ) is assigned to each of the form’s input fields. When Register is clicked, each field’s name and value are sent to the Web server.

form.html (3 of 4)

form.html (4 of 4)

15 Fig XHTML form for gathering user input.

Form Processing and Business Logic Business logic –Confirm that valid information was entered –extract function Creates variables corresponding to each key-value pair in array Easily retrieve all values sent to PHP page –Regular expressions very helpful –Do checks on client side where possible JavaScript Conserves server resources Ending a script –die function Remember to close all HTML tags

17 form.php (1 of 4) Function ereg is called to determine whether the phone number entered by the user is valid. The expression \( matches the opening parentheses of a phone number. We access the phone field’s value from form.html by using variable $phone. The parentheses in the expression must be followed by three digits ( [0-9]{3} ), a closing parenthesis, three digits, a literal hyphen and four additional digits.

18 form.php (2 of 4) Function die terminates script execution

19 form.php (3 of 4)

20 form.php (4 of 4)

Form Processing and Business Logic Obtaining user input through forms.

Verifying a Username and Password Private website –Only accessible to certain individuals –Encrypt username and password data when sending, storing and retrieving for increased security Implementing password checking –Login information stored in file fopen function Read, write, append modes –Store data using fputs \n newline character –Close files when done fclose function

Verifying a Username and Password Implementing password checking, cont. –Trim newline character chop function –Split string into substrings given a certain delimiter split function –If username/password match list, allow access

password.html (1 of 4)

password.html (2 of 4) Form data is posted to password.php.

password.html (3 of 4)

Verifying a Username and Password XHTML form for obtaining a username and password.

28 password.php (1 of 7) Variable names, when preceded by the logical negation operator ( ! ), return true if they are empty or set to 0. This checks if a user has submitted a form without specifying a username or password. Function fieldsBlank is called if the user has submitted an incomplete form to notify the user that all form fields must be completed. Function isset tests whether the user has pressed the New User button, indicating that a new user must be added. To add a new user, we open the file password.txt in append mode and assign the file handle that is returned to variable $file.

29 password.php (2 of 7) Print an error message and terminate script execution if the file cannot be opened. Function fputs writes the name and password to the text file.. Function userAdded is called to print a message to the user to indicate that the username and password were added to the file.

30 password.php (3 of 7) Before entering the while loop, variable $userVerified is set to 0. The while loop executes as long as the there are more lines in the file to read and variable $userVerified is still 0 or empty. Function fgets reads a line from the text file. The result is assigned to variable $line. Function chop removes the newline character from the end of the line. Function split is called to separate the string at the specified delimiter (in this case, a comma). The resulting array is stored in array $field. The username entered by the user is tested against the one returned in the text file (stored in the first element of the array). If they match, variable $userVerified is set to 1. Function checkPassword is called to verify the user’s password. Variable $PASSWORD and array $field are passed to the function. If function checkPassword returns true, function accessGranted is called to notify the client that permission has been granted. Otherwise, function wrongPassword is called.

31 password.php (4 of 7) After the while loop has executed, function fclose is called to close the file. If variable $userVerified has not been set to a value other than 0, function accessDenied is called to notify the client that access has been denied. Function checkPassword compares the user’s password to the password in the file. If they match, true is returned, whereas false is returned if they do not.

32 password.php (5 of 7) Function userAdded prints a message to the client indicating that the user has been added. Function accessGranted prints a message to the client indicating that permission has been granted.

33 password.php (6 of 7) Function wrongPassword prints a message to the client indicating that the password is invalid. Function accessDenied prints a message to the client indicating that access has been denied.

34 password.php (7 of 7) Function fieldsBlank prints a message to the client indicating that all form fields have not been completed.

Verifying a Username and Password Fig Verifying a username and password.

36 password.txt (1 of 1)

PHP Database ODBC ODBC is an Application Programming Interface (API) that allows you to connect to a data source (e.g. an MS Access database). Create an ODBC Connection With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available. Here is how to create an ODBC connection to a MS Access Database: 1.Open the Administrative Tools icon in your Control Panel. 2.Double-click on the Data Sources (ODBC) icon inside. 3.Choose the System DSN tab. 4.Click on Add in the System DSN tab. 5.Select the Microsoft Access Driver. Click Finish. 6.In the next screen, click Select to locate the database. 7.Give the database a Data Source Name (DSN). 8.Click OK.

PHP Database ODBC Connecting to an ODBC The odbc_connect() function is used to connect to an ODBC data source. The function takes four parameters: the data source name, username, password, and an optional cursor type. The odbc_exec() function is used to execute an SQL statement. Retrieving Records The odbc_fetch_row() function is used to return records from the result-set. This function returns true if it is able to return rows, otherwise false. Retrieving Fields from a Record The odbc_result() function is used to read fields from a record. This function takes two parameters: the ODBC result identifier and a field number or name.

PHP Database ODBC

How to Create Login Page in PHP/MySQL Creating Database and user table