PHP. www.venturenext.com Outline  What is PHP?  What can PHP do?  PHP Basics  PHP and Forms  Cookies and Sessions  Database Connections  Command.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Other Web Application Development Technologies. PHP.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
Quick and Dirty Intro to PHP By David Choffnes (content shamelessly ripped from the manual)
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Servlets and a little bit of Web Services Russell Beale.
Chapter 10 Maintaining State Information Using Cookies.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
PHP: Introduction By Trevor Adams.
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.
Modified from Moseley ’s sli desWeb Applications Development. Lecture 6 Slide 1 Lecture 6: More PHP Instructor: Dr. Mohammad Anwar Hossain.
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 MOHAMMED SHURRAB TO MISS/ RASHA ATTALLAH. What is PHP? Stands for "PHP Hypertext Preprocessor" Server-side scripting language HTML-embedded Supports.
Server- Side technologies Client-side vs. Server-side scripts PHP basic ASP.NET basic ColdFusion.
INTERNET APPLICATION DEVELOPMENT For More visit:
Dynamic Web Sites Chris North cs3724: HCI. Presentations matt ketner, sam altman, mike gordon Vote: UI Hall of Fame/Shame?
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
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.
PHP By Jonathan Foss.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Introduction to CS520/CS596_026 Lecture Two Gordon Tian Fall 2015.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
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.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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.
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,
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP – Hypertext Preprocessor.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Introduction to Dynamic Web Programming
DBW - PHP DBW2017.
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.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP / MySQL Introduction
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Lecture 5: Functions and Parameters
PHP an introduction.
Hypertext Preprocessor
Introduction to PHP.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

PHP

Outline  What is PHP?  What can PHP do?  PHP Basics  PHP and Forms  Cookies and Sessions  Database Connections  Command Line PHP  Other PHP capabilities  Useful Links Slide # 2

What is PHP??  PHP: Hypertext Preprocessor  PHP is a scripting language that allows you to create dynamic web pages  You can embed PHP scripting within normal html coding  PHP was designed primarily for the web  PHP includes a comprehensive set of database access functions Slide # 3

What can PHP do?  Server side scripting CGI Server module  Command line scripting  GUI applications  Some of the protocols PHP speaks: LDAP, IMAP, SNMP, NNTP, POP3, HTTP, CORBA, XML(SAX/DOM), Perl regular expressions, Cybercash payment, CyberMUT, VeriSign Payflow Pro, and most relational databases Slide # 4

PHP Basics PHP echos everything to standard output until it comes across special tags:,, <? if ($expression) { ?> This is true. <? } else { ?> This is false. <? } ?> Slide # 5

PHP Basics (contd.)  Comments:  // /* */ #  Variable Types  boolean $foo = True;  integer $a=1234; $a=0123; $a=0x1A;  float $a=1.234; $a=1.2e3; $a=7E-10;  string $name = 'MyName';  array $arr[key] = value;  object  Variables  All variables begin with $ and can contain letters,  digits and underscore (and no digit directly after the $)  The value of a variable is the value of its most recent assignment  Don’t need to declare variables  Variables have no intrinsic type other than the type of their current value  Can have variable variables $$variable  Like a pointer variable type; best to avoid Slide # 6

Predefined Variables  $GLOBALS  $_SERVER  $_GET  $_POST  $_COOKIE  $_FILE  $_REQUEST  $_SESSION Slide # 7

Variable scope  The scope of a variable is the context within which it is defined.  Within user-defined functions a local function scope is introduced. Any variable used inside a function is by default limited to the local function scope.  This is circumvented by using the “global” or “static” declaration: function Sum() { global $a, $b; $b = $a + $b; } Slide # 8

Control Strctures  if  else  elseif  while  do..while  for  foreach  break  continue  switch  declare  return  require()  include()  require_once()  include_once() Slide # 9

Functions Default argument values  function foo ($arg_1="value", $arg_2=7.3,..., $arg_n) Variable-length argument lists  func_num_args()  func_get_arg() function foo ($arg_1, $arg_2,..., $arg_n) { echo "Example function.\n"; return $retval; } function square ($num) { return $num * $num; } echo square (4); // outputs '16' Slide # 10

Objects Slide # 11 <?php class Cart { var $items; // Items in our shopping cart function Cart() { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; /* etc... */ } // Add $num articles of $artnr to the cart function add_item ($artnr, $num) { $this->items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item ($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } else { return false; } ?>

PHP and Forms Slide # 12 An example HTML form: Name: Username: Beer: Warthog Guinness Stuttgarter

PHP and Forms (contd.) Variables accessible in array.php:  $_POST[“personal”][“name”]  $_POST[“personal”][“ ”]  $_POST[“beer”]  $_POST[“username”] For more on HTML forms: Slide # 13

PHP and Forms (contd.) Passing variables from page to page: $username from array.php will be available for array2.php Array.php: ” Favorite Color: Slide # 14

A form processing example <? while($temp = each($_POST)) { echo "Variable $temp[‘key’] contains ” echo “ $temp[‘value’] "; } ?> Slide # 15

GET vs. POST  GET  Accessed through the $_GET variable  Puts variables in the URL  Doesn’t require user to click “reload” if they revisit a page with the “back” button  Good for passing small amounts of data  POST  Accessed through the $_POST variable  Passes variables in Content HTTP directive … not in URL  If a user clicks the “back” button, the browser will ask the user to reload the page  Good for passing large amounts of data, but may cause navigation problems Slide # 16

Cookies Cookies are useful for storing user info that should be retained from one page to the next. (Overcome the ‘stateless’ nature of the web) Cookies are written to the client’s hard drive. Problems:  User can disable cookies in the browser  Cookies may be viewed by other users  Can only store 20 cookies; max 4KB.  Some browsers may display incorrectly unless all options are set in setcookie() Slide # 17

Creating a Cookie setcookie(name,value,expiration); Eg, setcookie(“fruit”,”banana”,time()+3600); The cookies is called ‘fruit’ and has a value of ‘banana’; it will expire 1 hr from now. Cookie values are sent as part of the HTTP headers (transparent to user). No output should be sent to the browser (echo etc) until the cookie is set else cookie will not be set. Slide # 18

Cookie (contd.) Accessing A Cookie  $_COOKIE contains the value of every current cookie <? foreach ($_COOKIE as $name =>$value) echo “ $name => $value”; ?> Deleting a Cookie  Automatically deleted after expiration time  You can manually delete by setting negative time  setcookie(“username”,””,time()-3600); Slide # 19

Redirection Once login data is captured/validated then want to go to a new page.  Header(“Location: URL”); header("Location: General technique:  Site start page = login page  Login page validates user and set cookies  Redirect to new page  New page uses cookie data to access DB info Slide # 20

Sessions  Used to store state across pages  To save a variable simply set it in the $_SESSION variable:  $_SESSION[“username”] = $username;  To access a saved variable, access the $_SESSION variable:  $username = $_SESSION[“username”];  To remove a variable, unset the $_SESSION variable:  unset($_SESSION[“username”]);  Slide # 21

Databases and PHP  PHP can access many types of RDBMS’s MySQL, M$SQL, Oracle, Sybase, M$ Access, dBase, dbm, PostgreSQL  Use database independent interfaces  My inc.db.php script  DB.php in PEAR   ADODB  Slide # 22

Command Line PHP  What is this good for:  Parsing files to put into a database  Updating files with latest public version (cron job)  Anything you’d use a shell script or perl script to do!  Variables of use:  $argc, $argv[]  $stdin, $stdout, $stderr Slide # 23

Other PHP capabilities  IMAP  XML parsing  FTP  IRC  Java  LDAP  Mail  Ncurses  OpenSSL  Regular Expressions  Compression  PDF file generation  Shockwave Flash  COM and.NET objects  Password strength tests  CURL  Ecommerce protocols Slide # 24

Useful Links  PHP main site:   Zend’s PHP Intro:   PHPBuilder:  Slide # 25

Slide # 26 Thank You