8 th Semester, Batch 2008 Department Of Computer Science SSUET.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
PHP Reusing Code and Writing Functions.
More on PHP Coding Lab no. 6 Advance Database Management System.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
Tutorial 10 Programming with JavaScript
Intermediate PHP & MySQL
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
Kyle MacLachlan.  Used To Format a Date/Time  Syntax: › date(format,timestamp)  format: Required, specifies format  timestamp:Optional, specifies.
04/09/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
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.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP Advance. Agenda Server side Includes File Handling Cookies Sessions Error/Exception handling Database handling with MySQL sending.
1 Essential HTML coding By Fadi Safieddine (Week 2)
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
File IO and command line input CSE 2451 Rong Shi.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
1 Chapter 7 – Object-Oriented Programming and File Handling spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Storing and Retrieving Data
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
PHP Programming.
PHP 4 Files, Functions. Opening a File The fopen() function is used to open files in PHP. The first parameter of this function contains the name of the.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
LECTURE 4 Files, File open, Read, Write. File Upload - In this lecture we will teach you how to open, read, and close a file on the server. - PHP Open.
Lecture Note 8: ASP Including Files and The Global.asa file.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
PHP Error Handling Section :I Source: 1.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
12 – PHP Contd. Informatics Department Parahyangan Catholic University.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML Links HTML uses a hyperlink to another document on the Web.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
PHP-5- Working with Files and Directories. Reading Files PHP’s file manipulation API is extremely flexible: it lets you read files into a string or into.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
8 th Semester, Batch 2008 Department of Computer Science SSUET.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
PHP Form Processing * referenced from
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 2 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
UNIT-IV WT. Why use classes and objects? PHP is a primarily procedural language small programs are easily written without adding any classes or objects.
Chapter 6 Persistence-Saving and Retrieving Data
Web Design and Development
Web Design and Development
1 CHAPTER 10 ADVANCED PHP.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
>> PHP: HTML Integration
Advanced PHP Lecture by Nutthapat Keawrattanapat
<?php require("header.htm"); ?>
Building Web Applications
PHP-II.
PHP Parse error Fatal error Warning Notice Updated : August 23,2012
Presentation transcript:

8 th Semester, Batch 2008 Department Of Computer Science SSUET.

Server Side Includes (SSI) You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function. The two functions are identical in every way, except how they handle errors: include() generates a warning, but the script will continue execution require() generates a fatal error, and the script will stop These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages. Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).

PHP include() Function The include() function takes all the content in a specified file and includes it in the current file. If an error occurs, the include() function generates a warning, but the script will continue execution. Example 1 Assume that you have a standard header file, called "header.php". To include the header file in a page, use the include() function: Welcome to my home page! Some text.

Example 2 Assume we have a standard menu file, called "menu.php", that should be used on all pages: Home Tutorials References Examples About Us Contact Us

Example 2 All pages in the Web site should include this menu file. Here is how it can be done: Welcome to my home page. Some text.

Example 2 If you look at the source code of the page above (in a browser), it will look like this: Home Tutorials References Examples About Us Contact Us Welcome to my home page! Some text.

PHP require() Function The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop. Error Example include() Function

Error message: Warning: include(wrongFile.php) [function.include]: failed to open stream: No such file or directory in C:\home\website\test.php on line 5 Warning: include() [function.include]: Failed opening 'wrongFile.php' for inclusion (include_path='.;C:\php5\pear') in C:\home\website\test.php on line 5 Hello World! Notice that the echo statement is executed! This is because a Warning does not stop the script execution.

Error Example require() Function Now, let's run the same example with the require() function.

Error message: Warning: require(wrongFile.php) [function.require]: failed to open stream: No such file or directory in C:\home\website\test.php on line 5 Fatal error: require() [function.require]: Failed opening required 'wrongFile.php' (include_path='.;C:\php5\pear') in C:\home\website\test.php on line 5

Error message: The echo statement is not executed, because the script execution stopped after the fatal error. It is recommended to use the require() function instead of include(), because scripts should not continue after an error.

PHP File Handling Opening a File The fopen() function is used to open files in PHP. The first parameter of this function contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened:

Example The following example generates a message if the fopen() function is unable to open the specified file:

Closing a File The fclose() function is used to close an open file:

Check End-of-file The feof() function checks if the "end-of-file" (EOF) has been reached. The feof() function is useful for looping through data of unknown length. Note: You cannot read from files opened in w, a, and x mode! if (feof($file)) echo "End of file";

Reading a File Line by Line The fgets() function is used to read a single line from a Note: After a call to this function the file pointer has moved to the next line. Example The example below reads a file line by line, until the end of file is reached: "; } fclose($file); ?>

Reading a File Character by Character The fgetc() function is used to read a single character from a file. Note: After a call to this function the file pointer moves to the next character. Example The example below reads a file character by character, until the end of file is reached: