Lecture 2 Unix and PHP. INLS 523 Web Databases Spring 2013 Rob Capra

Similar documents
Lecture 5 Security and User Input. INLS 760 Web Databases Spring 2013 Rob Capra

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

What is PHP? [1] Figure 1 [1]

PHP 5 if...else...elseif Statements

Introduction to Databases. Key Concepts. Calling a PHP Script 5/17/2012 PHP I

Programming for the Web with PHP

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Lecture 12. PHP. cp476 PHP

CSC Web Programming. Introduction to JavaScript

PHP Hypertext Preprocessor

PHP 1. Introduction Temasek Polytechnic

PHP. MIT 6.470, IAP 2010 Yafim Landa

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 (

CERTIFICATE IN WEB PROGRAMMING

Creating HTML files using Notepad

CPSC 481: CREATIVE INQUIRY TO WSBF

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

cis20.2-spring2010-sklar-lecii.4 1

"Charting the Course... Intermediate PHP & MySQL Course Summary

PHP 101. Function Junction. Mike Pavlak Solutions Consultant (815) All rights reserved. Zend Technologies, Inc.

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

Princess Nourah bint Abdulrahman University. Computer Sciences Department

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

PHP by Pearson Education, Inc. All Rights Reserved.

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

B. V. Patel Institute of BMC & IT 2014

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

Web development using PHP & MySQL with HTML5, CSS, JavaScript

Sections and Articles

Important Points about PHP:

Lecture 6 Session Control and User Authentication. INLS 760 Web Databases Spring 2013 Rob Capra

Arithmetic and Assignment Operators

Server side basics CS380

Basic PHP Lecture 17

PHP. Interactive Web Systems

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

Web Engineering (Lecture 08) WAMP

Web Scripting using PHP

Lecture (05) PHP 01. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Spring 2016, Web Programming

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server

Chapter 2: Functions and Control Structures

DevShala Technologies A-51, Sector 64 Noida, Uttar Pradesh PIN Contact us

Subject Name: Advanced Web Programming Subject Code: (13MCA43) 1. what is PHP? Discuss different control statements

M275 - Web Development using PHP and MySQL

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

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

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

CGS 3066: Spring 2015 JavaScript Reference

Review. Fundamentals of Website Development. Web Extensions Server side & Where is your JOB? The Department of Computer Science 11/30/2015

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

Core PHP. PHP output mechanism. Introducing. Language basics. Installing & Configuring PHP. Introducing of PHP keywords. Operators & expressions

Chapter 11 Outline. A Simple PHP Example Overview of Basic Features of PHP Overview of PHP Database Programming. Slide 11-2

Get in Touch Module 1 - Core PHP XHTML

C-LANGUAGE CURRICULAM

PHP 101 for IBM i. Mike Pavlak, Solution Consultant Zend Technologies, Inc.

Lecture 7 PHP Basics. Web Engineering CC 552

USQ/CSC2406 Web Publishing

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

Programming for Experimental Research. Flow Control

PHP & My SQL Duration-4-6 Months

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Minor Subject

Web Scripting using PHP

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Submitting forms (client-side)

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. magic_quotes_runtime = Off

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2017

(Frequently Asked Questions)

PHP for PL/SQL Developers. Lewis Cunningham JP Morgan Chase

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

Web Development. with Bootstrap, PHP & WordPress

Professional Course in Web Designing & Development 5-6 Months

Part I. Web Technologies for Interactive Multimedia

4th year. more than 9 years. more than 6 years

Suppose for instance, that a client demands the following page (example1.php).

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

PHP. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

PHPoC vs PHP > Overview. Overview

COMS 469: Interactive Media II

Final Exam. IT 3203 Introduction to Web Development. Rescheduling Final Exams. PHP Arrays. Arrays as Hashes. Looping over Arrays

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

Computer Science E-75 Building Dynamic Websites

CICS 515 b Internet Programming Week 2. Mike Feeley

Web Programming Paper Solution (Chapter wise)

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Homework 4: Comparing Search Engine Ranking Algorithms

JavaScript and PHP. JavaScript and PHP. DD1335 (Lecture 8) Basic Internet Programming Spring / 26

G I F T U N I V E R S I T Y

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

Lab 4: Basic PHP Tutorial, Part 2

PHP Dynamic Web Pages, Without Knowing Beans

Autopopulation; Session & Cookies

NETB 329 Lecture 13 Python CGI Programming

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum: Homepage:

Fachgebiet Technische Informatik, Joachim Zumbrägel

Transcription:

Lecture 2 Unix and PHP INLS 523 Web Databases Spring 2013 Rob Capra

Server-Side Scripting Server-side scripting Scripts run on the server Scripts return HTML to the client Apache Open-source Perl and PHP are well-supported Internet Information Services (IIS) Microsoft ASP is well-supported

Server-Side Scripting Client Browser (2) Apache finds foo.php on disk (1) GET foo.php / HTTP 1.1 Internet A p a c h e Web Server PHP (3) Apache calls PHP to process foo.php (4) PHP sends output back to Apache (5) Apache sends PHP output as HTTP response to client foo.php bar.html Server Storage

Web Scripting with PHP Hello world script: lect2/helloworld.php echo "Hello world"; Look at the HTML output Web browser, view source

PHP References http://us1.php.net/manual/en/index.php http://www.w3schools.com/php/default.asp

Variables in PHP: PHP Variables Start with a dollar sign: $a, $foo, $numparts Have a data type: Integer, float, string, boolean, array, object Are loosely (weakly) typed $ricky = 3; // $ricky is an integer $lucy = 3.14; // $lucy is a float $ethel = friend ; // $ethel is a string

Variable Scope Built-in superglobals are available everywhere $GLOBALS, $_GET, $_POST, $_COOKIE, $_SESSION Global vs local scope: $lucy = 5; $ricky = 10; $fred = $lucy+$ricky; ethel(); lect2/scope1.php function ethel () { $lucy=100; $ricky=200; $fred = $lucy + $ricky; echo $fred; echo "\n"; echo $fred; echo "\n"; Note: run these programs from the command-line with: -q = quiet mode -n = no php.ini php qn foo.php

This is a little gross, but... Variable Variables lect2/varvar.php $lucy = 5; echo $lucy. "\n"; $ethel="lucy"; $$ethel=10; echo $lucy. "\n"; Note the $$

Constants Have scope everywhere (inside and outside fns) define('lucy', 5); define('ethel', 10); lect2/constants.php echo LUCY. "\n"; function ricky () { echo ETHEL. "\n"; ricky();

Arithmetic operators + - * / % Operators String operator: concatenation. Assignment operators = += -= *= /= %=.= Assignment returns a value Pre- and post-increment and decrement ++ -- $a = 5; $b = 10; $ricky = "Hello "; $lucy = "world"; $c = $a * $b; $d = $b * ($f=$b); echo $c. "\n"; echo $d. "\n"; echo ++$d. "\n"; lect2/operators.php $fred = $ricky. $lucy; echo $fred. "\n";

Comparison operators More operators ==!= <> < > <= >= ===!== Caution: $a=$b evaluates to true for all values of $a and $b Logical operators &&! Bitwise operators & ~ ^ << >>

Many string functions Strings http://us1.php.net/manual/en/ref.strings.php $a = 5; $b = 10; $ricky = "ricky"; echo strlen($ricky). "\n";; echo substr($ricky, 1, 4). "\n";

Conditionals $fred=5; $lucy=10; lect2/conditionals.php if ($lucy>$fred) { echo "lucy is greater\n"; if ($lucy>$fred) { echo "lucy is greater or equal\n"; else { echo "fred is greater\n"; if ($lucy>$fred) { echo "lucy is greater\n"; elseif ($lucy==$fred) { // remember == echo "both are equal\n"; else { echo "fred is greater\n";

Switch $lucy=2; $lucy='ethel'; lect2/switch.php switch ($lucy) { case 1: echo "lucy is 1\n"; break; case 2: echo "lucy is 2\n"; break; case 'ethel': echo "lucy is ethel\n"; break; default: echo "default\n"; break;

While Loops $fred=1; Starting value End condition lect2/while.php while ($fred<=10) { echo $fred. "\n"; $fred++; Increment

For Loops echo "Loop test<p>"; Starting expression End condition lect2/forloop.php for($i=0;$i<=9;$i++) { echo "i = $i<br>"; Iterator expression

PHP Arrays Arrays in other languages: a[1] = 1; a[2] = 3; a[3] = 5; PHP arrays are more like pairings: force["luke"] = 3; force["ben"] = 5; force["yoda"] = 10; force["vader"] = -8; PHP arrays are mappings of keys to values.

PHP Arrays Mapping of keys to values. Keys can be integers or strings lect2/array1.php $fred = array(2 => 3, 3 => 5, 4 => 7); lect2/array2.php $fred[2] = 3; $fred[3] = 5; $fred[4] = 7; These two methods generate the same array. Check with: print_r($fred);

PHP Arrays Values can be any data type, including another array! Can create multi-dimensional arrays. lect2/array3.php $fred = array(2 => 3, "life" => 42, "inls760isfun" => true, 14 => array( 1 => 3, 2 => 5)); print_r($fred);

PHP Arrays When using arrays that have string keys Always use quotes: $force["luke"] = 3; $force['luke'] = 3; $force[luke] = 3; OKAY OKAY WRONG!!!

Sorting Arrays $fred = array ( "760" => "WebDB", "523" => "DB", "780" => "ResMeth", "582" => "SysAnal", "500" => "HII" ); lect2/asort.php print_r($fred); asort($fred); print_r($fred); ksort($fred); print_r($fred);

Foreach Loops $fred[2] = 3; $fred[3] = 5; $fred[4] = 7; foreach($fred as $ethel) { print "$ethel\n"; foreach($fred as $lucy => $ethel) { print "$lucy = $ethel\n"; lect2/foreach1.php

HTML: lect2/form1.html HTML Forms and PHP <head> <title>html Forms and PHP Test 1</title> </head> <body> <h1>html Forms and PHP Test 1</h1> <form method="post" action="form1.php"> Name: <input type="text" name="name"> <p> Course: <input type="text" name="course"> <p> <input type="submit" value="send"> </form> </body> 23

$_GET and $_POST PHP superglobal associative arrays Hold information sent from an HTML form PHP automagically places each form variable value into: $ _GET[formvariablename] or $_POST[formvariablename] 24

HTML Forms and PHP PHP: lect2/form1.php echo "Hello, ". htmlspecialchars(strip_tags($_get['name'])); echo "<br>"; echo "You are in the course: ". htmlspecialchars(strip_tags($_get['course'])); 25

Dropping in and out of PHP PHP: lect2/form2.php <h1>form 2 test</h1> Hello, htmlspecialchars(strip_tags($_get['name'])); <br> You are in the course: htmlspecialchars(strip_tags($_get['course'])); Two changes from form1.php: 1) GET instead of POST 2) PHP mixed with HTML 26

PHP Functions PHP functions: lect2/func1.php function print_course_title() { echo "<h1>inls 760 Web Databases</h1>"; print_course_title(); 27

PHP Functions PHP functions: lect2/func2.php function print_course_title() { <h1>inls 760 Web Databases</h1> print_course_title(); 28

PHP Functions PHP functions: lect2/func3.php function print_square($num) { echo $num*$num; 29

Code reuse with require PHP require: lect2/require1.php require "func3.php"; print_square(1); echo "<p>"; print_square(2); echo "<p>"; print_square(3); echo "<p>"; print_square(4); echo "<p>"; 30

Site design fun with functions PHP site design: lect2/sitefunc.php function page_template() { <head> <title>inls 760</title> </head> <body> <h1>inls 760</h1> page_content(); </body> 31

Site design fun with functions PHP site design: lect2/sitepage1.php require "sitefunc.php"; function page_content() { This is where the <b>content</b> for this page would go. page_template(); 32

lect2/readfile1.php $lines = file("data1.txt"); foreach ($lines as $line) { $fields = explode(",",$line); foreach ($fields as $field) { echo "$field"; echo "\n"; Reading from a file 33

Reading from a file PHP site design: lect2/readfile1.php <h1>reading a file test 1</h1> <table> $lines = file("data1.txt"); foreach ($lines as $line) { echo "<tr>"; $fields = explode(",",$line); foreach ($fields as $field) { echo "<td>"; echo "$field"; echo "</td>"; echo "</tr>"; </table> data1.txt: luke,skywalker,3 ben,kenobe,5 yoda,yoda,10 darth,vader,-8 34