Error Handling, Exception. Pemrograman Web

Similar documents
Chapter 8: Error Handling and Debugging

PERU BAHAN PERKHIDMATAN KREDIT DAN PERBANKAN ARAHAN KERJA UNIT KOMPUTER. Tatacara Proses AGM03. BPKP/KJAK-104 Bilangan Semakan : 0 Tarikh :

Semasa buku ini ditulis XAMPP mengandungi empat versi:

Pratikum 8. Membuat Transaksi Penjualan

Error Handling and Debugging

PHP Directory Functions With Examples pdf

zend. Number: Passing Score: 800 Time Limit: 120 min.

3.0 PERKHIDMATAN RANGKAIAN

exam. Number: Passing Score: 800 Time Limit: 120 min File Version: Zend Certified Engineer

CARA-CARA UNTUK MEMBUAT POSTER MELALUI PERISIAN PHOTOSHOP. Untuk membuat poster sediakan beberapa bahan seperti berikut:

COMP284 Scripting Languages Lecture 10: PHP (Part 2) Handouts

An Overview of Protocols and Function

Standard Error Processing Rogue Wave Software, Inc. All Rights Reserved. 1

Deep Dive into Logging and Error Handling. Miro Dietiker (miro_dietiker) Eric Peterson (iameap)

PHP with data handling

UNIT III Open Source Programming Languages - PHP

CPET 499/ITC 250 Web Systems. Topics

P - 13 Bab 10 : PHP MySQL Lanjut (Studi Kasus)

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

INSTRUCTION: This section consists of TWO (2) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi DUA (2) soalan. Jawab SEMUA soalan.

LAMPIRAN A PROGRAM FLOWSTONE

INSTRUCTION: This section consists of TWO (2) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi DUA (2) soalan. Jawab SEMUA soalan.

Scaffold Documentation

Visitor Management System

Pengenalan Sistem Maklumat Dalam Pendidikan

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

B. V. Patel Institute of BMC & IT 2014

LXXVIII. Session handling functions

Zend EXAM Zend Certified PHP Engineer. Buy Full Product.

System Error Code 1 Means Incorrect Function.

ioncube Loader 10 User Guide

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

PHP & My SQL Duration-4-6 Months

How to test and debug a PHP project In particular, proj2. Slide 1

The Perl Debugger. Avoiding Bugs with Warnings and Strict. Daniel Allen. Abstract

Purpose. Target Audience. Prerequisites. What Is An Event Handler? Nagios XI. Introduction to Event Handlers

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo

HOSTING PLANS & FEATURES

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

Solar Plant Data Acquisition Maintenance

PHP INTERVIEW QUESTION-ANSWERS

Php Manual Header Redirect After 5 Seconds Using

HOSTING PLANS & FEATURES

Panduan Menggunakan Autoresponder FreeAutobot.com

PERKHIDMATAN KREDIT DAN PERBANKAN PROSEDUR UNIT KOMPUTER. Proses Backup ( Windows) BPKP/KlOK-118 Bilangan Semakan : Q Tarikh :

[PDF] PHP MYSQL SCHOOL MANAGEMENT SYSTEM

ssk 2023 asas komunikasi dan rangkaian TOPIK 4.0 PENGALAMATAN RANGKAIAN Minggu 11

Listing Progam. Universitas Sumatera Utara

Some things to watch out for when using PHP and Javascript when building websites

How to test and debug a PHP project In particular, proj2

Using Tcl. Learning Objectives

(Frequently Asked Questions)

Lecture 3: Web Servers / PHP and Apache. CS 383 Web Development II Monday, January 29, 2018

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

PHP Reference. To access MySQL manually, run the following command on the machine, called Sources, where MySQL and PhP have been installed:

Professional Course in Web Designing & Development 5-6 Months

Zend Zend PHP 5.

1. Name: 3. BEM Registration No.: Tel. No. :... Mobile Phone No. : :... Fax No. :...

ioncube Loader 6.0 User Guide

DC71 INTERNET APPLICATIONS JUNE 2013

PANDUAN PENGGUNA (PENSYARAH)

M275 - Web Development using PHP and MySQL

8. Control statements

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

41% Opens. 73% Clicks. 35% Submits Sent

DOKUMEN TIDAK TERKAWAL

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

M.C.A. (Sem.-IV) (CRCS) Examination May-2014 Paper CCA4004 : Web Programming - I. Faculty Code: 003 SUbject Code:

Discovering Computers Living in a Digital World

REGISTRATION GUIDE MCIS CUSTOMER PORTAL. Page 1

A Crash Course in Perl5

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3

Security issues. Unit 27 Web Server Scripting Extended Diploma in ICT 2016 Lecture: Phil Smith

PHP Dynamic Web Pages, Without Knowing Beans

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Pemrograman Jaringan Web Client Access PTIIK

Current trends: Scripting (I) A bid part of interface design centers around dialogs

BORANG PENGESAHAN STATUS TESIS

belajar html5 158E7F2D743EA866244C3EE391F064DC Belajar Html5 1 / 6

Zend Zend PHP 5.3 Certification.

PHP: The Basics CISC 282. October 18, Approach Thus Far

B,8 PERKHIDMATAN KREDIT DAN PERBANKAN. Pemindahan Data PROSEDUR UNIT KOMPUTER. BPKP/KlOK-117 Bilangan Semakan : 0 Tarikh : PERUBAHAN.

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2018

Preview from Notesale.co.uk Page 1 of 167

INSTRUCTION: This section consists of FOUR (4) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi EMPAT (4) soalan. Jawab SEMUA soalan.

This tutorial will guide you how to setup and run your own minecraft server on a Linux CentOS 6 in no time.

TSS Rental Software Solutions. What to? A Tape drive, USB Key, CD/DVD, External Hard Drive, Off Site backup, or any other reliable media.

HTML 5 Form Processing

Basic Shell Commands. Bok, Jong Soon

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

MySQL for Developers Ed 3

Winscp Cannot Create Remote File Error Code 4

COMP1730/COMP6730 Programming for Scientists. Exceptions and exception handling

Database Connectivity using PHP Some Points to Remember:

PHP. Interactive Web Systems

Vendor: Zend. Exam Code: Exam Name: Zend Certified PHP Engineer. Version: Demo

Manual Pengguna. PCN Online Service Fulfillment System

Introduction. 1. Deactivating Anti-Executable Enterprise. 2. Updating the virus definitions 3. Reactivating Anti-Executable Enterprise.

Exception Codes and Module Numbers Used in Cisco Unified MeetingPlace Express

bash Scripting Introduction COMP2101 Winter 2019

Transcription:

Error Handling, Exception Pemrograman Web

PHP Error Handling When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Common error checking methods in PHP Simple "die()" statements Custom errors and error triggers Error reporting

Basic Error Handling using the die() function The first example shows a simple script that opens a text file: <?php $file=fopen("welcome.txt","r");?> If the file does not exist you might get an error like this: Warning: fopen(welcome.txt) [function.fopen]: failed to open stream: No such file or directory in C:\webfolder\test.php on line 2

How to prevent To prevent the user from getting an error message like the one above, we test whether the file exist before we try to access it: <?php if(!file_exists("welcome.txt")) { die("file not found"); else { $file=fopen("welcome.txt","r");?> Now if the file does not exist you get an error like this: File not found

Creating a Custom Error Handler Creating a custom error handler is quite simple. We simply create a special function that can be called when an error occurs in PHP. This function must be able to handle a minimum of two parameters (error level and error message) but can accept up to five parameters (optionally: file, line-number, and the error context): Syntax error_function(error_level,error_message, error_file,error_line,error_context)

Error Report levels

How to create a function to handle errors function customerror($errno, $errstr) { echo "<b>error:</b> [$errno] $errstr<br>"; echo "Ending Script"; die(); The code above is a simple error handling function. When it is triggered, it gets the error level and an error message. It then outputs the error level and message and terminates the script. Now that we have created an error handling function we need to decide when it should be triggered.

Set Error Handler The default error handler for PHP is the built in error handler. It is possible to change the error handler to apply for only some errors, that way the script can handle different errors in different ways. in this example we are going to use our custom error handler for all errors: set_error_handler("customerror"); Since we want our custom function to handle all errors, the set_error_handler() only needed one parameter, a second parameter could be added to specify an error level.

Example <?php //error handler function function customerror($errno, $errstr) { echo "<b>error:</b> [$errno] $errstr"; //set error handler set_error_handler("customerror"); //trigger error echo($test);?> The output of the code above should be something like this: Error: [8] Undefined variable: test

Trigger an Error <?php $test=2; if ($test>=1) { trigger_error("value must be 1 or below");?> Notice: Value must be 1 or below in C:\webfolder\test.php on line 6 Possible error types: E_USER_ERROR - Fatal user-generated run-time error. Errors that can not be recovered from. Execution of the script is halted E_USER_WARNING - Non-fatal user-generated run-time warning. Execution of the script is not halted E_USER_NOTICE - Default. User-generated run-time notice. The script found something that might be an error, but could also happen when running a script normally

Example <?php //error handler function function customerror($errno, $errstr) { echo "<b>error:</b> [$errno] $errstr<br>"; echo "Ending Script"; die(); //set error handler set_error_handler("customerror",e_user_warning); //trigger error $test=2; if ($test>=1) { trigger_error("value must be 1 or below",e_user_warning);?> The output of the code above should be something like this: Error: [512] Value must be 1 or below Ending Script

Error Logging PHP sends an error log to the server's logging system or a file, depending on how the error_log configuration is set in the php.ini file. By using the error_log() function you can send error logs to a specified file or a remote destination. <?php //error handler function function customerror($errno, $errstr) { echo "<b>error:</b> [$errno] $errstr<br>"; echo "Webmaster has been notified"; error_log("error: [$errno] $errstr",1, "someone@example.com","from: webmaster@example.com"); //set error handler set_error_handler("customerror",e_user_warning); //trigger error $test=2; if ($test>=1) { trigger_error("value must be 1 or below",e_user_warning);?> The output of the code above should be something like this: Error: [512] Value must be 1 or below Webmaster has been notified And the mail received from the code above looks like this: Error: [512] Value must be 1 or below

Soal Buatlah program untuk error handling, dengan kondisi seperti berikut: 2 digit terakhir NRP mahasiswa antara 35 s.d 40 Tanggal yang diinputkan > date() Buat program mengirimkan error handling ke email d4b@pens.ac.id, dari email admin@pens.ac.id, untuk kondisi seperti berikut: Range IP Address yang diperbolehkan : 10.252.44.130 10.252.44.150 Nama domain komputer yang diperbolehkan: D4ITA D4ITB D3ITA D3ITB

Reference https://www.w3schools.com/