Web Programming with PHP 5. The right tool for the right job.

Similar documents
HTML Tables. IT 3203 Introduction to Web Development

CS412 Interactive Lab Creating a Simple Web Form

Short notes on webpage programming languages

Working with forms in PHP

Web Development 1 A4 Project Description Web Architecture

Introduction to Server-Side Programming. Charles Liu

Script Handbook for Interactive Scientific Website Building

Website Planning Checklist

Real SQL Programming 1

PHP Tutorial From beginner to master

Introduction to XHTML. 2010, Robert K. Moniot 1

Internet Technologies

Chapter 22 How to send and access other web sites

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Introduction to Web Design Curriculum Sample

Web Design Basics. Cindy Royal, Ph.D. Associate Professor Texas State University

A table is a collection of related data entries and it consists of columns and rows.

Programming the Web 06CS73 SAMPLE QUESTIONS

HTML Forms and CONTROLS

Embedding a Data View dynamic report into an existing web-page

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Designing for Dynamic Content

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

PHP Authentication Schemes

LAB MANUAL CS (22): Web Technology

AJAX The Future of Web Development?

People Data and the Web Forms and CGI. HTML forms. A user interface to CGI applications

JavaScript: Arrays Pearson Education, Inc. All rights reserved.

CSCI110: Examination information.

About webpage creation

HTML5 and CSS3 Part 1: Using HTML and CSS to Create a Website Layout

WHITEPAPER. Skinning Guide. Let s chat Velaro info@velaro.com by Velaro

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

So we're set? Have your text-editor ready. Be sure you use NotePad, NOT Word or even WordPad. Great, let's get going.

HTML Basics(w3schools.com, 2013)

DESIGNING HTML HELPERS TO OPTIMIZE WEB APPLICATION DEVELOPMENT

JavaScript and Dreamweaver Examples

Chapter 2: Interactive Web Applications

Cisco Adaptive Security Appliance (ASA) Web VPN Portal Customization: Solution Brief

Website Login Integration

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

10CS73:Web Programming

Facebook Twitter YouTube Google Plus Website

Accessibility in e-learning. Accessible Content Authoring Practices

Client-side Web Engineering From HTML to AJAX

Server-side scripting with PHP4

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

Chapter 2 HTML Basics Key Concepts. Copyright 2013 Terry Ann Morris, Ed.D

Dynamic Web-Enabled Data Collection

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

2- Forms and JavaScript Course: Developing web- based applica<ons

In order for the form to process and send correctly the follow objects must be in the form tag.

Further web design: HTML forms

Web Application Guidelines

How to Display Weather Data on a Web Page

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

Server-side: PHP and MySQL

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

By Glenn Fleishman. WebSpy. Form and function

Hello World RESTful web service tutorial

PHP Framework Performance for Web Development Between Codeigniter and CakePHP

ITNP43: HTML Lecture 4

Web Server Lite. Web Server Software User s Manual

EUROPEAN COMPUTER DRIVING LICENCE / INTERNATIONAL COMPUTER DRIVING LICENCE WEB EDITING

WEB DESIGN LAB PART- A HTML LABORATORY MANUAL FOR 3 RD SEM IS AND CS ( )

Example. Represent this as XML

Campaign Guidelines and Best Practices

«W3Schools Home Next Chapter» JavaScript is THE scripting language of the Web.

WIRIS quizzes web services Getting started with PHP and Java

Novell Identity Manager

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

Part II of The Pattern to Good ILE. with RPG IV. Scott Klement

Sample HP OO Web Application

A Brief Introduction to MySQL

PHP and XML. Brian J. Stafford, Mark McIntyre and Fraser Gallop

Cover Page. Dynamic Server Pages Guide 10g Release 3 ( ) March 2007

Last week we talked about creating your own tags: div tags and span tags. A div tag goes around other tags, e.g.,:

Server side scripting and databases

Web application development (part 2) Netzprogrammierung (Algorithmen und Programmierung V)

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Java Server Pages and Java Beans

Web Design Revision. AQA AS-Level Computing COMP2. 39 minutes. 39 marks. Page 1 of 17

How to Make a Working Contact Form for your Website in Dreamweaver CS3

PEAR. PHP Extension and Application Repository. Mocsnik Norbert Harmadik Magyarországi PHP Konferencia március 12., Budapest

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

Web development... the server side (of the force)

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

HTML TIPS FOR DESIGNING

CIS 467/602-01: Data Visualization

Transcription:

Web Programming with PHP 5 The right tool for the right job.

PHP as an Acronym PHP PHP: Hypertext Preprocessor This is called a Recursive Acronym GNU? GNU s Not Unix! CYGNUS? CYGNUS is Your GNU Support

Why the Name Matters PHP PHP: Hypertext Preprocessor Hypertext is just HTML Preprocessor is important for PHP Lexical Substitution Conditions and File Includes Similar to C++ Preprocessor...

How PHP Works WEB SERVER Source File The purpose of a web server is precisely to send HTML to the browser! PHP Apache/ IIS HTML

Why do we care? 100% Platform-Independent for the user No additional style or content-arrangement concerns Intelligent application design: How much is done by server? Understand: Goofy animations are done with Javascript, Flash, whatever. PHP is for page content.

HTML Syntax: Block Items Comments: <!--... --> <head> contains information for the browser <body> contains information to display. End tags with </tag> or with start tag: <tag /> <html> <head> <title>my Awesome Site</title> </head> <body> </body> </html> <!-- A Picture --> <img src= me.jpg /> <!-- A Paragraph --> <p>my Sexy Photograph</p> <!-- A Box --> <div style= border-style: dotted > <p> Tack in the Box <br /> Twice! </p> </div>

Example: html_1.html <html> <head> <title>my Awesome Site</title> </head> <body> </body> </html> <!-- A Picture --> <img src= me.jpg /> <!-- A Paragraph --> <p>my Sexy Photograph</p> <!-- A Box --> <div style= border-style: dotted > <p> Tack in the Box <br /> Twice! </p> </div>

HTML Syntax: Tables Tables have Rows, Header Cells, and Data Cells Good style and closing tags are important for legibility In the past, people laid out their web pages with tables: AVOID THIS MIGHTILY! <html> <head> <title>coding Contest</title> </head> <body> </body> </html> <!-- A Chart --> <table> <tr> <th> Winner </th> <th> Loser </th> </tr> <tr> <td> Tack </td> <td> Joel </td> </tr> </table>

Example: html_2.html <html> <head> <title>coding Contest</title> </head> <body> </body> </html> <!-- A Chart --> <table> <tr> <th> Winner </th> <th> Loser </th> </tr> <tr> <td> Tack </td> <td> Joel </td> </tr> </table>

HTML Syntax: Forms Forms are used a lot in PHP Open/close with <form> tags, use <input... /> tags inbetween. Arrange the inputs like regular box items. Note the method and action attributes <html> <head> <title>forms</title> </head> <body> </body> </html> <!-- A Form --> <form method= post action= forms.html > Name: <input name= name type= text /> Good?: <input name= male type= checkbox /> </form>

Last Word: CSS I am not teaching HTML or CSS; it is a pain and it is outside the scope of this talk. CSS is not perfect; you will end up blending old stuff with as much CSS as you can. Armed with this basic HTML background, we can now introduce some PHP Syntax!

Basic PHP Syntax Always start, end with <?php...stuff...?> Syntax draws heavily from C Declare a variable by naming them with a dollar sign. All lines end with a semicolon Output HTML using echo <html>... <body>... <?php $name = Bob the Fish ; $age = 11; $dog_age = $age * 7; echo $name; echo is ; echo $dog_age; echo in Dog Years. ;?>... </body> </html>

<?php // Create a variable $myvariable; // Do things to variables $augend = 3; $addend = 5; $sum = $addend + $augend; $also_sum = $augend; $also_sum += $addend; $zero = 0; $one = ++$zero; // Variables can be anything! $integer = 52; $floatvalue = 15.62364; $stringvalue = Good Night Nurse ; $boolvalue = true; Variables Variables in PHP are Un-typed Declare variables by naming them All variable names start with a dollar sign Standard operations: = + - * / % ++ --?>

<?php // Example control statements if ( $meal == Steak ) echo Yum! ; else echo Blugh! ; switch ( $beverage ) { case wine : $BAC = 0.03; break; } case jungle juice : $BAC = 0.23; echo Death! ; break; for ( $i = 1; $i < 5; ++$i ) echo $i; // Special comparison example if ( 1 === true ) echo Big problems. ; Control Statements All the regulars reappear: if, else if, else, for(), while() Comparison operators: < > ==!= >= <=... New comparison: ===!== (compares value and type) Compare strings by dictionary order with strcmp()?>

<?php // A Simple String echo I am a simple string! ; // Concatenation echo A. meets. B ; // Concatenation and assignment $string1 = dog ; $string2 = fleas ; $uglydog = $string1. $string2; echo $string1; // Outputting with tags and // Interpolating variables echo <p> My dog is cute. </p> ; echo I said $string1 ; echo I said $string1 ; echo I have two {$string1}s ;?> Strings Strings are the single most essential core component Concatenation Operator:. When writing a web script, use PHP to output HTML tags, too. Single-Quote Strings are taken 99% Literally Double-Quote Strings will interpolate variables automatically

EXAMPLE 1: Obfuscated PHP Code!

Arrays in PHP There are two types of arrays: Numeric and Associative Numeric arrays: Indexed by numbers, starting at 0 Associative arrays: Key-Value pairs PHP defines a special for() loop especially for arrays... Numeric Index Value 0 12345 1 Fish swim good. 2 [SimpleXML Object]...... Associative Key Value First Name Hootie Last Name Blowfish Species Salmon......

<?php // Using Arrays $meals = array( Steak, Cat ); $steak_meal = $meals[0]; $defs = array( Steak => Good, Cat => Dry & Bony ); $review = $defs[$steak_meal]; // The foreach loop foreach ( $meal as $food ) echo I want $food. <br /> ; foreach ( $defs as $food => $rev ) echo $food is $rev <br /> ; // Special Arrays, examples $_SERVER[ PHP_SELF ]; $_GET[ firstname ]; $_POST[ submit_check ];?> Arrays and the foreach() Loop Construct arrays with array() The foreach() loop iterates through all defined members of the array. PHP also defines special global arrays, including the ones you see here. Remember: Arrays are just a particular type of variable

EXAMPLE 2: What are $_POST and $_GET

Functions <?php Functions in PHP, like in Javascript, are very flexible and easy to write Variable scope plays an important role (as always) The only tricky thing: default parameters... function header( $title ) { echo <<<HEADER <html> <head> <title> $title </title> </head> HEADER; } // Another function function multiply( $a, $b ) { return $a * $b; } // Function calls header( Tack is Dating a Cow ); echo multiply( 127, 23 );?>

That is Basic PHP! You know all the core components of syntax. To read detail about PHP, http://www.php.net/ is an excellent source; documentation and function reference. From now forward, in this talk, we look at some of the cool things PHP can do. Something new to PHP 5: Object-Oriented Design

XML: What is it? Works like HTML, Syntax-wise Purpose: To store information in a predictable fashion, without dealing with databases. Pros: Really easy to parse. Cons: Size kills speed. <?xml version= 1.0?> <staff> <person> <lastname>adve</lastname> <firstname>sarita</firstname> <title>associate Professor <office>4110 SC</office> </title> </person> <person> <lastname>adve</lastname> <firstname>vikram</firstname> <title>assistant Professor </title> <office>4235 SC</office> </person>... </staff>

SimpleXML: Really simple. <?php These functions come with PHP 5 (One of the big changes) Syntax is modeled after C++ pointer-member access SimpleXML builds an array of each element; we can iterate! // Start by loading the string or file $xml = simplexml_load_string ($xmlstring); // Now we want to echo everybody s // last name in paragraphs. foreach ($xml->person as $guy) { echo <p> ; echo $guy->lastname; echo </p>\n } // Now say we just want the fifth // person s last name: echo <p> FIFTH: ; echo $xml->person[4]; echo </p>\n ;?>

MySQL: Really Powerful SQL is a language; MySQL is a database. SQL instructions are meant to read like sentences. Information in tables, tables in databases <?php // Connect and Select the database mysql_connect( localhost, admin, mypassword ); mysql_select_db( awesome_db ); // Now let s grab a name $name = Joel ; $result = mysql_query( SELECT age FROM people WHERE name= $name ; ); $age = mysql_fetch_assoc($result); echo $age[ age ]; Name Age Height Tack 19 64?> Joel 19 34