CGS 3066: Web Programming and Design Spring 2016 PHP.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

PHP I.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Objectives Using functions to organize PHP code
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
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.
COM336 – Web Database Development XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKPRO GUIDE Chapter 2: Programming with PHP Copyright © 2012 by Larry Ullman Dr. Mogeeb Mosleh Saturday ( pm)
JavaScript, Fourth Edition
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.
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Chapter 8 Cookies And Security JavaScript, Third Edition.
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.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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 PHP supports.
Week 4 PHP H ypertext P reprocessor Reference : Official Site :
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to PHP.
הרצאה 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.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
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.
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,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Introduction to Dynamic Web Programming
CS 371 Web Application Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Arrays An array in PHP is an ordered map
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
PHP Hypertext Preprocessor
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
PHP an introduction.
Client-Server Model: Requesting a Web Page
PHP-II.
Web Programming and Design
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

CGS 3066: Web Programming and Design Spring 2016 PHP

PHP Capabilities ● Generate dynamic page content ● Create, open, read, write, delete, and close files on the server. ● Collect form data. ● Manage cookies and sessions. ● Add, delete, modify data in database. ● User management (i.e. restrict users to access some specific webpages)

PHP files ● PHP files can contain text, HTML, CSS, JavaScript, and PHP code ● PHP code are executed on the server, and the result is returned to the browser as plain HTML ● PHP files have extension ".php" Image Source:

PHP Syntax ● A PHP script can be placed anywhere in the document ●..even before ● A PHP script starts with : ● contains commands separated by ; ● A PHP file normally contains HTML tags, and some PHP scripting code. My first PHP page <?php echo "Hello World!"; ?>

PHP Comments <?php // This is a single line comment # This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ ?>

Variables in PHP ● A variable starts with the $ sign, followed by the name of the variable. ● A variable name must start with a letter or the underscore character. ● A variable name cannot start with a number. ● A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ ). ● Variable names are case sensitive ($y and $Y are two different variables).

PHP Case Sensitivity In PHP, all user-defined functions, classes, and keywords NOT case sensitive (unlike Javascript) <?php ECHO "Hello World! "; echo "Hello World! "; EcHo "Hello World! "; ?>

PHP Operators Various operators can be used in PHP ● Arithmetic: +,-,*,/,**,% ● Assignment: =, +=, -=, *=, /=, %= ● String:.(concatenation),.= ● Increment/decrement: ++ and -- (post and pre) ● Relational: ==, ===, !=, !==,, >=, <> ● Logical: and, &&, or, ||, xor, ! ● Array: +, ==, ===, !=, <>, !==

Conditional Statements ● if... ● if … else … ● if … elseif … else … <?php if ($a > $b) { echo "a is bigger than b"; } elseif ($a == $b) { echo "a is equal to b"; } else { echo "a is smaller than b"; } ?> ● additional control structures(If necessary):

Loops ● while : $x = 2; while ($x < 1000) { echo $x. “\n”; // \n is newline character $x = $x * $x; } ● do...while: do { echo $x. “\n”; $x = $x * $x; } while ($x < 1000); // note the semicolon

Loops(Contd.) ● for: for ($i = 1; $i <= 10; $i++) { echo $i. “\n”;//prints 1 through 10, one number per line } ● foreach ( works only on arrays and objects): $arr = array(1, 2, 3, 4); foreach ($arr as $value) { //$value corresponds to each element in $arr echo $value “\n”; }

PHP Functions ● The real power of PHP comes from its functions; it has more than 1000 built-in functions. ● Besides the built-in PHP functions, we can create our own functions. ● Example: <?php function foo ($x, $y) { echo “example function \n”; echo $x + $y. \n”; return $x + $y; //optional } ?> … <?php foo(3,4);//prints 7 $retval = foo(5,6);// prints 11, copies 11 to $retval ?>

Indexed Arrays in PHP Maintains a list of values using the same variable name and unique index array() function is used to create an array $colors = array(“blue”,”yellow”, “pink”); echo $colors[0]; //prints ‘blue’ echo $colors[2]; //prints ‘pink’ To append an element to the array: $colors[] = “purple”;// adds purple at $color[3] To remove an element from the array, use unset(): unset($colors[2]);// also removes the index 2 from array

Associative Arrays in PHP keep track of a set of unique keys and the values that they associate to – called an associative array Same array()function, different syntax $myarray = array( "foo" => "bar", "bar" => "foo", ); To add an element to the array, use a new key value: $myarray[“newkey”] = “new value”;// adds purple at $color[3] Use isset() function to test if a variable/keyed value exists of not: isset($myarray[“bar”]); //function returns true isset($myarray[“barr”]); //function returns false

The for-each loop with PHP arrays Easy way to iterate over all elements of an array Example, iterate and print all elements of an indexed array: $colors = array(“blue”,”yellow”, “pink”);//indexed array foreach ($colors as $color) { echo $color; // simply prints each color } foreach ($colors as $indexno => $color) { echo “$indexno => $color ”; // prints color with index } $myarray = array("foo" => "bar", "bar" => "foo");//associative array foreach ($myarray as $key => $value) { echo “$key => $value ”; // prints values with key }

Collect Form data in PHP

Superglobals A collection of associative arrays those can be accessed from anywhere in PHP file $GLOBALS//array of all variables in ‘global scope’( not belonging to any function scope ) $_SERVER// Server and execution environment information $_GET// HTTP GET variables $_POST//HTTP POST variables $_FILES// HTTP File Upload variables $_COOKIE// HTTP Cookies $_SESSION// Session variables $_REQUEST// contains a copy of contents of $_GET, $_POST and $_COOKIE $_ENV//environment variables (information passed from web server shell environment) Source:

Forms with PHP Form data is sent to the server when the user clicks “Submit”. The PHP superglobals $_GET and $_POST are used to collect form-data (depending on the method attribute of the submitted form) $_GET array populated from the URL of the submitted form. Example: maps $_GET[“fname”] to “john”, $_GET[“lname”] to “doe” $_POST is an array of variables passed to the current script via the HTTP POST method.

$_GET vs. $_POST $_GET: HTTP GET requests can be cached, bookmarked GET requests are limited by the length of the URL No privacy, not suitable for user authentication $_POST: Cannot by cached, browser must make request to the server with form data Cannot be bookmarked Used to submit sensitive information No limit on the posted data volume

Example: client.html Executing on Client Side Name:

Example: server.php Executing on the Server Side The name that was submitted was:

Example: self-submit form value Name <?php if(isset($_POST['submit'])) //tests if the submit button is clicked or not { $name = $_POST['name']; echo “From Server: The name that was submitted was: $name "; echo " You can use the above form again to enter a new name."; } ?>