PHP Hypertext Preprocessor - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

PHP Hypertext Preprocessor

Description:

Programming basics but a scripting language. Code interpreted, not pre-compiled ... Watch this space for late-breaking news. about the course. ... – PowerPoint PPT presentation

Number of Views:349
Avg rating:3.0/5.0
Slides: 22
Provided by: ValuedGate1387
Category:

less

Transcript and Presenter's Notes

Title: PHP Hypertext Preprocessor


1
PHP- Hypertext Preprocessor
  • COSC 418
  • Design of Multiplayer Games
  • K. Harmeyer

2
Scripting
  • Programming basics but a scripting language
  • Code interpreted, not pre-compiled
  • Client-side scripting Scripts processed by web
    browser Typically JavaScript
  • Server-side scripting Scripts evaluated and
    processed by script engine Includes Perl, JSP,
    CFM, ASP, and PHP

3
PHP Hypertext Preprocessor
  • A recursive name!
  • An interpreted language
  • A scripting language
  • Syntax similar to C and Perl
  • Used to develop server-side scripts
  • Complete, standalone scripts
  • Scripted elements embedded in HTML
  • Tightly integrated with Apache and MySQL

4
PHP Hypertext Preprocessor
  • Identified by special characters lt?php ?gt
  • Characters offset or escape code from HTML
  • Contents evaluated as PHP code
  • All code must be in form of Expressions
    Functions Conditions Loops

5
Basic HTTP Conversation
6
HTTP Conversation with Script Execution
7
Scripting with PHP
  • Simple expressions with comments
  • // store the value 6 into a variable named
    amountamount 6
  • // store the value Maggie into a variable named
    namename Maggie
  • /add 4 to the value stored in amount and store
    the result in a variable named total. Notice the
    multi-line comment/total 4 amount

8
What is It?
  • PHP pages are normal HTML pages with PHP commands
    inserted into them.
  • The Web server preprocesses the page and converts
    the page to HTML then sends it to the browser.

9
Sample hello.php
  • lthtmlgt ltheadgt  lttitlegtPHP Testlt/titlegt
    lt/headgt ltbodygt  lt?php echo 'ltpgtHello
    Worldlt/pgt' ?gt lt/bodygt
  • lt/htmlgt
  • The file is parsed by PHP and sent to the browser.

10
HTML Delivered to Browser
  • lthtmlgt
  • ltheadgt
  • lttitlegtPHP Testlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltpgtHello Worldlt/pgt
  • lt/bodygt
  • lt/htmlgt

11
What Does it Do?
  • Serverside scripting
  • Dynamic Web content
  • Connects with server files, text and MySQL
  • Generates HTML documents on the fly
  • Your COSC 418 Web pages
  • Command line scripting
  • Manage server tasks from the command line
  • Client-side GUI applications
  • PHP-GTK

12
We Care Because
  • Wide ranging support for databases
  • http//ccbc-elnx.ccbcmd.edu/kharmeyer/plpsites.ph
    p
  • Easy additions/deletions
  • Template use for similar pages
  • http//iat.ubalt.edu/courses/cosc418.001_sp07
  • Easy updates

13
Origins of PHP
  • Rasmus Lerdorf
  • Concept -1994
  • PHP 1.0 1995 Personal Home Page tools
  • Open Source
  • Current version PHP 5.2.1 release 2/14/2007
  • Now runs on Apache, Microsoft IIS and Netscape
    servers.
  • Free!
  • www.php.net

14
What Do You Need?
  • Apache Server Version 2.2.6
  • www.apache.org
  • PHP Version 5.2.4
  • www.php.net
  • MySQL Version 4.1
  • http//dev.mysql.com/downloads/mysql/4.1.html

15
index.php
  • lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN"gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtCOSC 418 Welcome Pagelt/titlegt
  • ltlink rel"stylesheet" type"text/css"
    href"project.css"gt
  • lt/headgt
  • ltbody bgcolor"ffffff"gt
  • ltcentergt
  • lttable width"800" cellpadding5gt
  • lt?php include ("titles.html") ?gt
  • lttrgt
  • lttd valign"top" bgcolor"70b8c9"gt lt?php
    include("menu.html") ?gt lt/tdgt
  • lttdgt ltp align"right"gtltspan
    id"subhead"gtMondays, 200 -430
  • pm ltbrgt
  • Academic Center 219
  • lt/spangtlt/pgt
  • ltp align"left"gtltspan
    id"paragraph"gtThis is the home page for the
    Design
  • of Multiplayer Games course. Watch
    this space for late-breaking news
  • about the course. Use the menu at the
    left to access course materials.lt/spangtlt/pgt

16
Page Counter for Webpage Access
  • What would we need?

17
Page Counter for Webpage Access
  • Need a text file on server with count in it.
  • Need PHP code in Web page to
  • Access current count in text file on server
  • Get current count
  • Increment the count
  • Save text file with updated count on server.

18
PHP Script
  • counterScript.php
  • lt?php
  • // Page access counter include script in page
    to be counted
  • // EDIT KMH 5/20/2001
  • // initialize variables ensure there is a file
    named counter.txt on the server in same folder
  • TextFile "counter.txt"
  • Counter trim(file_get_contents(TextFile))
  • // Access current count in text file on server
  • FilePointer fopen(TextFile, "r")
  • // Get current count
  • Counterfgets(FilePointer, 1024)
  • fclose (FilePointer)
  • // Increment the count
  • settype(Counter, "integer")
  • Counter

19
PHP file to Activate Counter
  • counter.php
  • lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN"gt
  • lthtmlgt
  • ltheadgtlttitlegtPage Counterlt/titlegtlt/headgt
  • ltbodygt
  • The number of hits for this page is lt?php include
    (counterScript.php) ?gt
  • lt/bodygt
  • lt/htmlgt
  • In Class Activity
  • Add this counter to your cosc418 index page.

20
High Scores List
  • Think about an algorithm for managing a high
    scores list for a PHP game.
  • Write the steps you would need to program to
    accommodate a high scores feature.
  • Bring the algorithm to class next week.

21
How to Get Started
  • Read Chapter 2 Language Basics
  • Note how the syntax is similar to C
  • Note what is different
  • Look at course site.
  • Selected PHP source files are available for view
    in PHPsource sub folder.
  • Download and install free Apache/PHP/MySQL
  • Edit your homework pages
  • Create a Look and put it in a titles.html file
  • Include that file in each of your homework pages.
  • lt?php include(titles.html") ?gt
Write a Comment
User Comments (0)
About PowerShow.com