CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

 HTTP Communication  HTTP Communication for Web  Static  Dynamic  Dynamic Content  PHP  PHP Block  PHP Programming Style  Database  MySQL.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Copyright 2009 Justin C. Klein Keane PHP Code Auditing Session 1 – PHP Foundations Justin C. Klein Keane
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Server side basics.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
PHP - Hypertext Preprocessor Yaron Benita De Paul University.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Website Development PHP Roundup. PHP Basics This presentation covers the key features of PHP without getting into the way we use it in collaboration with.
1 Pertemuan 13 PHP-MySQL Last Updated: 15 th May 2010 By M. Arief
ITD 3194 Web Application Development Chapter 4: Web Programming Language.
Mandakini Ayushi Infotech Mandakini Kumari 22 nd July PHP Basic.
Lecture 12 PHP Basics Boriana Koleva Room: C54
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
An Introduction to PHP The University of Tennessee at Chattanooga C. Daniel Chase “An introduction to basic PHP use with a focus on the power of dynamic.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Web Programming by Aryo Pinandito 01 – PHP Fundamentals and State.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
Technical Review - PHP Jang Jaeseok. Overview Introduction  What is PHP?  History of PHP  What can do with PHP?  Advantages of PHP PHP syntax.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Lecture 10 – MYSQL and PHP (Part 2)
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
PHP A very brief introduction PHP1. PHP = PHP: Hypertext Processor A recursive acronym! PHP scripts are executed on the server side Executed by (a plugin.
Martin Kruliš by Martin Kruliš (v1.1)1.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
CHAPTER 7 Introduction to PHP5 Part II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
By bscshelp.com 1.  It is a group assignment.  Complete Website design Using Html and Css.  Due date: 10 th December, 2014 (Hard Deadline) 2.
PHP using MySQL Database for Web Development (part II)
PHP (Session 1) INFO 257 Supplement.
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
PHP Introduction.
ITS332.
Software Engineering for Internet Applications
PHP.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
PHP an introduction.
Presentation transcript:

CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles

PHP Personal Home Page Tools by Rasmus Lerdorf in 1995 PHP: Hypertext Preprocessor by Andi Gutmans and Zeev Suraski 1998 PHP PHP PHP 5 PHP usage million domains 1.2+ million ip addresses

Hello World PHP Hello World <?php echo " Hello World! "; ?>

Development Environment Text editor + Web Server + PHP On CS3  $HOME/public_html/hello.php  Eclipse PHP IDE Zend Debugger 

PHP as a Programming Language Comments Literals Variables Operators Expressions Statements Functions Classes

Comments Script style: # single-line comment C++ style: // single-line comment C style: /* single-line comment */ /* multiple-line comments */

Literals 123, 0123, 0x “123”, ‘123’ true, false null

Heredoc Syntax for String A “Here document” Example: echo <<<HTML Username: Password: HTML;

Variables and Constants Starts with a $ Variables names are case-sensitive Variable reference & Constant define( name, value ) E.g. define( TITLE, “PHP Test Page”)

Example: Variable and Variable Reference $a = “hello”; $b = “world”; $a = $b; $b = 10; echo $a; $a = “hello”; $b = “world”; $a = &$b; $b = 10; echo $a;

Operators Arithmetic +, -, *, /, % Assignment = +=, -=, *=, /=, %=.= Increment/decrement ++, -- Concatenation. Comparison ==, != >, >=, <, <= Logical &&, ||, ! Conditional ?:

Example: Operators $a = “hello”; $b = “world”; if( $a ”; $c = $a + “ ” + $b; echo $c; $c = $a. “ ”. $b; echo $c; $a.= $b;

Control Statements Branch if if … else if…elseif…else Switch switch Loop while do … while for foreach Break and continue break continue

Example: Switch Statement switch( $fruit ) { case “apple”: echo “The fruit is an apple”; break; case “pear”: echo “The fruit is a pear.”; break; default: echo “The fruit is not an apple or a pear.”; }

Arrays Associative arrays, like Map in Java Key must be either integer or string

Example: Arrays $courses = array( “cs320” => “web”, “cs122” => “SQL” ); $strings[“a”] = “abc”; $strings[1] = “def”; # when key is omitted $numbers1 = array( 1, 2, 3, 4, 5 ); $numbers2 = array( 1 => 1, 2 => 2, 3, 4, 5 => 5 ); $strings[] = “xyz”; $strings[] = “uvw”;

Example: Access Array Elements echo $numbers1[2], “ ”; echo $courses[“cs320”], “ ”; foreach( $courses as $key => $value ) echo “$key, $value ”; foreach( $numbers as $n ) echo “$n ”; for( $i = 0 ; $i < count($numbers) ; ++$i ) echo $numbers[$i];

Some Useful Array Functions Remove an element unset() Number of elements count(), sizeof() Sort By value: asort(), arsort() By key: ksort(), krsort()

Example: Array Functions foreach( $strings as $key => $value ) echo $key, " ", $value, " "; asort($strings); foreach( $strings as $key => $value ) echo $key, " ", $value, " "; ksort($strings); foreach( $strings as $key => $value ) echo $key, " ", $value, " ";

Functions function sum( $op1, $op2 ) { return $op1 + $op2; } function say_hello() { echo "hello."; }

About Functions Functions can be defined pretty much anywhere in the code E.g. in other functions or in an if statement Functions have global scope No function overloading, and no way to undefine or redefine a function Support variable functions

Example: Variable Function function sum ($a, $b) { return $a + $b; } $v = “s”.“u”.“m”; echo $v(1,3);

Basic Class Syntax class GuestBookEntry { private $name; public $comment; function __construct( $name, $comment ) { $this->name = $name; $this->comment = $comment; } function getName() { return $this->name; } function setName( $name ) { $this->name = $name; } }

Using Objects $entry = new GuestBookEntry( “cysun”, “hello” ); echo $entry->getName(), “ says ”, $entry->comment;

Include Other Files include(), include_once() require(), require_once()

PHP as a Web Programming Language Handle HTTP requests Generate HTTP response Session tracking Database access

Example: GuestBook without Database Store an array of GuestBookEntry in session scope – there is no application scope in PHP

Pre-defined Variables $_GET $_POST $_REQUEST $_COOKIE $_SESSION $_SERVER

Access Request and Session Variables if( ! empty ($_REQUEST[“submit”]) ) { $name = $_SESSION[“name”]; if( empty ($name) ) { $name = $_REQUEST[“name”]; $_SESSION[“name”] = $name; }

Override Default Settings php.inicode display_errors = Off error_reporting = E_ALL session.auto_start = 0 ini_set(“display_errors”, 1); error_reporting(E_ERROR); session_start(); = 0

Example: GuestBook with Database Using MySQL database $connection = mysql_connect("localhost", "cs320stu31", "abcd"); mysql_select_db( "cs320stu31", $connection ); $result = mysql_query( "select * from guest_book" ); $entries = array(); while( $row = mysql_fetch_array($result) ) $entries[] = new GuestBookEntry( $row["name"], $row["comments"] ); mysql_close( $connection );

Handle Query Results $result$row namecomment cysunHello steveNice page! “name” => “cysun” “comment” => “Hello” 1 => “cysun” 2 => “Hello” mysql_fetch_array()

Variations of mysql_fetch_array() Fetch a row as an associative array mysql_fetch_array($result, MYSQL_ASSOC ) mysql_fetch_assoc($result) Fetch a row as an integer-indexed array mysql_fetch_array($result, MYSQL_NUM ) mysql_fetch_row($result)

More MySQL Functions ysql.php

About PHP Advantages Easy to learn Easy to use Dynamic typing Web-friendly language features Disadvantages??

Resources PHP Manual -