Error Handling and Validation

Slides:



Advertisements
Similar presentations
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Advertisements

An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Asp.NET Core Vaidation Controls. Slide 2 ASP.NET Validation Controls (Introduction) The ASP.NET validation controls can be used to validate data on the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
JavaScript, Third Edition
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Chapter 12: Exception Handling
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Exceptions Handling Exceptionally Sticky Problems.
Introduction to Exception Handling and Defensive Programming.
JavaScript and PHP Validation and Error Handling CHAPTER 17.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Module 6 – Generics Module 7 – Regular Expressions.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company ASP.NET Validation Control Presented By : Muhammad Atif Hussain Deputy.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
7 Copyright © 2009, Oracle. All rights reserved. Regular Expression Support.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Linux+ Guide to Linux Certification, Second Edition
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
PHP Exception Handling How to handle and create user-defined exceptions Mario Peshev Technical Trainer Software University
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Linux Administration Working with the BASH Shell.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
Validation Controls Assist your users with providing the correct type of input for your application Assist your users with providing the correct type of.
Web Database Programming Using PHP
JavaScript.
CS 330 Class 7 Comments on Exam Programming plan for today:
Working with Java.
Looking for Patterns - Finding them with Regular Expressions
Handling Exceptionally Sticky Problems
Web Database Programming Using PHP
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 ©
Indexer AKEEL AHMED.
Web Programming– UFCFB Lecture 17
Intro to PHP & Variables
Working with Forms and Regular Expressions
Exception Handling Chapter 9.
Exceptions Problems in a Java program may cause exceptions or errors representing unusual or invalid processing. An exception is an object that defines.
Exception Handling Chapter 9 Edited by JJ.
Part B – Structured Exception Handling
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Boolean Expressions to Make Comparisons
Lecture 25: Regular Expressions
Chapter 3: Selection Structures: Making Decisions
Handling Exceptionally Sticky Problems
Exception Handling.
Presentation transcript:

Error Handling and Validation Chapter 15

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

What Are Errors and Exceptions? Types of Errors Expected errors Warnings Fatal errors

What Are Errors and Exceptions? Types of Errors

What Are Errors and Exceptions? An exception refers to objects that are of type Exception and which are used in conjunction with the object-oriented try . . . catch language construct for dealing with runtime errors.

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

PHP Error Reporting The error_reporting Setting error_reporting specifies which type of errors are to be reported ini_set('log_errors','1'); It can also be set within the php.ini file: log_errors = On

PHP Error Reporting The display_errors Setting The display_error setting specifies whether error messages should or should not be displayed in the browser ini_set('display_errors','0'); It can also be set within the php.ini file: display_errors = Off

PHP Error Reporting The log_errors Setting The log_errors setting specifies whether error messages should or should not be sent to the server error log. ini_set('log_errors','1'); It can also be set within the php.ini file: log_errors = On

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

PHP Error and Exception Handling Procedural Error Handling $connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME); $error = mysqli_connect_error(); If ($error != null) { // handle the error ... }

PHP Error and Exception Handling Object-Oriented Exception Handling Exception throwing function (for illustration purposes) function throwException($message = null,$code = null) { throw new Exception($message,$code); } try { // PHP code here $connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or throwException("error"); ... catch (Exception $e) { echo ' Caught exception: ' . $e->getMessage(); echo ' On Line : ' . $e->getLine(); echo ' Stack Trace: '; print_r($e->getTrace()); } finally { // PHP code here that will be executed after try or after catch

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

Regular Expressions A regular expression is a set of special characters that define a pattern. Regular expressions are a concise way to eliminate the conditional logic that would be necessary to ensure that input data follows a specific format. PHP, JavaScript, Java, the .NET environment, and most other modern languages support regular expressions (each slightly different)

Regular Expressions Regular Expression Syntax A literal is just a character you wish to match in the target A metacharacter is a special symbol that acts as a command to the regular expression parser . [ ] \ ( ) ^ $ | * ? { } + Regular Expression Patterns can be combined to form complex expressions

Regular Expressions Regular Expression Syntax Patterns ^ qwerty $ If used at the very start and end of the regular expression, it means that the entire string (and not just a substring) must match the rest of the regular expression contained between the ^ and the $ symbols. \t Matches a tab character. \n Matches a new-line character. . Matches any character other than \n.

Regular Expressions Regular Expression Syntax Patterns [qwerty] Matches any single character of the set contained within the brackets. [^qwerty] Matches any single character not contained within the brackets. [a-z] Matches any single character within range of characters. \w Matches any word character. Equivalent to [a- zA-Z0-9]. \W Matches any nonword character.

Regular Expressions \s Matches any white-space character. Regular Expression Syntax Patterns \s Matches any white-space character. \S Matches any nonwhite-space character. \d Matches any digit. \D Matches any nondigit. * Indicates zero or more matches. + Indicates one or more matches. ? Indicates zero or one match.

Regular Expressions {n} Indicates exactly n matches. Regular Expression Syntax Patterns {n} Indicates exactly n matches. {n,} Indicates n or more matches. {n, m} Indicates at least n but no more than m matches. | Matches any one of the terms separated by the | character. Equivalent to Boolean OR. () Groups a subexpression. Grouping can make a regular expression easier to understand.

Regular Expressions Extended Example ^(\(?\s*\d{3}\s*[\)–\.]?\s*)?[2-9]\d{2}\s*[–\.]\s*\d{4}$

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

Validating User Input Required information Correct data type Types of Input Validation Required information Correct data type Correct format Comparison Range Check Custom

Validating User Input Notifying the User

Validating User Input How to Reduce Validation Errors – show where error located

Validating User Input How to Reduce Validation Errors – providing textual hints

Validating User Input How to Reduce Validation Errors – use tool tips

Validating User Input How to Reduce Validation Errors – use input masks

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

Where to Perform Validation

Where to Perform Validation Validation at the JavaScript Level Client process Can reduce server load Can be bypassed

Where to Perform Validation Validation at the PHP Level Validation on the server side using PHP is the most important form of validation and the only one that is absolutely essential.

1 2 3 4 5 6 7 Chapter 15 PHP Error Reporting Regular Expressions What Are Errors and Exceptions? PHP Error Reporting PHP Error and Exception Handling 3 4 Regular Expressions Where to Perform Validation 5 6 Validating User Input 7 Summary

Summary Key Terms CAPTCHA error exception expected error fatal errors literal metacharacter regular expression spam bots warnings

Summary Questions?