Introduction to PHP To boldly go where JavaScript has never been…

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 1 Introduction to Perl and CGI.
PHP I.
Introduction to JavaScript
PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
1 Chapter 12 Working With Access 2000 on the Internet.
Creating WordPress Websites. Creating a site on your computer Local server Local WordPress installation Setting Up Dreamweaver.
Internet – Part II. What is the World Wide Web? The World Wide Web is a collection of host machines, which deliver documents, graphics and multi-media.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Web Programming Introduction to PHP COM Objectives To understand what PHP is and how a PHP script works with a Web Browser and a Web Server To learn.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
ITM352 Javascript and Dynamic Web Pages: Client Side Processing.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Web Page A page displayed by the browser. Website Collection of multiple web pages Web Browser: A software that displays web pages on client computer.
Web Design Scripting and the Web. Books on Scripting.
4.1 JavaScript Introduction
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.
BMES514 – Fall 2010 David R. Brooks Institute for Earth Science Research and Education
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
CPS120: Introduction to Computer Science The World Wide Web Nell Dale John Lewis.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 21 - Web Servers (IIS, PWS and Apache) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3.
Introduction to PHP – Chapter 8 Working with PHP.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
HTML. Principle of Programming  Interface with PC 2 English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine Code.
Web Interfaces, Forms & Databases Databases Snyder p HTML Basics Snyder p JavaScript Snyder Chapter 18.
1 Welcome to CSC 301 Web Programming Charles Frank.
CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
Introduction to JavaScript CS101 Introduction to Computing.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
WAMP Windows Apache MySQL and PHP i.e. “WAMP”. Why WAMP? WampServer is a Windows web development environment. It allows you to create and test web pages.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
NASRULLAH KHAN.  Lecturer : Nasrullah   Website :
COMP 2923 A2 Website Development 101 Danny Silver JSOCS, Acadia University.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Invitation to Computer Science 6 th Edition Chapter 10 The Tower of Babel.
PHP Security Ryan Dunn Jason Pack. Outline PHP Overview PHP Overview Common Security Issues Common Security Issues Advanced Security Issues Advanced Security.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
PHP using MySQL Database for Web Development (part II)
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to Dynamic Web Programming
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
Web Development Web Servers.
Introduction to ASP By “FlyingBono” 2009_01 By FlyingBono 2009_01
Chapter 2 Client/Server Applications
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Section 17.1 Section 17.2 Add an audio file using HTML
PHP Introduction.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Tonga Institute of Higher Education IT 141: Information Systems
JavaScript.
PHP and Forms.
Tonga Institute of Higher Education IT 141: Information Systems
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Client-Server Model: Requesting a Web Page
Web Servers (IIS and Apache)
Introduction to JavaScript
Web Application Development Using PHP
Presentation transcript:

Introduction to PHP To boldly go where JavaScript has never been…

JavaScript vs. PHP JavaScript is a client-side language that resides in your browser. It is available for use with no effort on your part. PHP must be installed on a server (local or remote), and you must have specific permissions to access PHP applications. JavaScript cannot access any information outside an HTML document. PHP applications can access and create files stored elsewhere in a server.

A typical server-side problem: A user enters information about measurements taken with a sun-viewing instrument (a sun photometer) that is used to measure total column water vapor in the atmosphere. The information provided by the user consists of the instrument’s serial number, the location and time of the measurements, and voltage outputs from the instrument. The application must use this information to find the location of the sun at the time and place of the measurement and then calculate total column water vapor based on calibration constants stored for the instrument used to collect the data.

The data file might look like this: SN A B C beta tau WV WV … WV …

The HTML document: Document 1.1. (getCalib.htm) Get calibration constant document.write("This document last modified on "+document.lastModified+".") Get calibration constants for water vapor instrument Enter serial number here:

Steps to using PHP 1.Install a server on a computer (local or remote). 2.ownload and install a PHP interpreter. 3.Configure the server to recognize PHP documents and to locate the PHP interpreter. 1. Setting up a PHP environment.

Steps to using PHP 2. Creating, editing, and executing PHP documents. 1.PHP documents are text files that can be created with any text editor. (A “real” code editor such as AceHTML is better.) 2. Figure out where to store PHP documents. With the WAMP server, they are stored in /wamp/www. 3. Create and edit PHP documents in an editor. 4. Execute the documents from your browser. With Windows IIS the “URL” is localhost/ {PHP file name}. 5. Make required changes in your editor and “refresh” the application in your browser.

Steps to using PHP 3. Passing information from an HTML Document to a PHP application. By design, this is very easy to do in PHP! The statement Automatically passes all form field values to the PHP document to a system-defined array called $_POST. In the PHP document, $SN=$_POST[“SN"]; retrieves the instrument serial number passed from Document 1.1.

Looking for a match… Document 1.2. (getCalib.php) <?php // Extract instrument ID from POST data… $SN=$_POST["SN"]; $len=strlen($SN); // Open WV instrument calibration constant file… $inFile = "WVdata.dat"; $in = fopen($inFile, "r") or exit("Can't open file"); // Read one header line… $line=fgets($in); // Search rest of file for SN match… $found=0; while ((!feof($in)) && ($found == 0)) { $values=fscanf($in,"%s %f %f %f %f %f"); list($SN_dat,$A,$B,$C,$beta,$tau)=$values; if (strncasecmp($SN_dat,$SN,$len)==0) $found=1; } fclose($in);

Several ways to read data from file… $values=fscanf($in,"%s %f %f %f %f %f"); list($SN_dat,$A,$B,$C,$beta,$tau)=$values; $line=fgets($in); list($SN_dat,$A,$B,$C,$beta,$tau)=sscanf($line,"%s %f %f %f %f %f"); Read values from the file into an array, according to a specified format. Then assign the elements to named variables: Read an entire line as a string and then read values from the string according to a specified format: fscanf($in,"%s %f %f %f %f %f",$SN_dat,$A,$B,$C,$beta,$tau); Read an entire line and assign named variables directly, according to a specified format:

Processing the data… if ($found == 0) echo "Couldn't find this instrument."; else { // Build table of outputs… echo " Quantity Value "." "; echo " Instrument ID $SN "; echo " Calibration Constants "; echo " A $A "; echo " B $B "; echo " C $C "; echo " τ $tau "; echo " β $beta "; echo " "; } ?>

Saving your results on a server… $inFile = "WVdata.dat"; $outFile="WVreport.csv"; $in = fopen($inFile, "r") or exit("Can't open file."); $out=fopen( "c:/Documents and Settings/All Users/Documents/PHPout/".$outFile,"a"); fprintf($out, "Data have been reported for: %s,%f,%f,%f,%f,%f\n", $SN,$A,$B,$C,$tau,$beta); fclose($out);

Solving a quadratic equation For the quadratic equation ax 2 + bx + c = 0, find the real roots: r1 = [-b + (b2 – 4ac)1/2 ]/2a r2 = [-b - (b 2 – 4ac)1/2 ]/2a The “a” coefficient must not be 0. If the discriminant, b 2 – 4ac = 0, there is only one root. If the discriminant is less than 0, there are no real roots.

Document 1.6a (quadrat.htm) Solving the Quadratic Equation Enter coefficients for ax 2 + bx + c = 0: a = (must not be 0) b = c =

Document 1.6b (quadrat.php)

Preventing multiple form submissions Document 1.7a (WeatherReport.htm) Weather Report var alreadySubmitted = false; function submitForm ( ) { if (alreadySubmitted) { alert("Data already submitted. Click on 'Reset Button' and start over." ); return false; } else { alreadySubmitted = true; return true; } }

Multiple submissions, part 2 Report weather observations <form method="post" action="WeatherReport.php" onSubmit="return submitForm(this.form);" > Date (mm/dd/yyyy) : Time (UT hh:mm:ss): Air temperature (deg C): Barometric pressure (millibar): Cloud cover (octas 0-8): Precipitation today (total mm): This code allows only one “submit,” after which you have to click the Reset button. Note that this is a JavaScript solution, but the problem often occurs when you are submitting data to a PHP application that appends to an existing file.