CS 330 Class 7 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

CS 330 Class 7

Description:

... Programming PHP in TA office. Reference: www.php.net. Begin ... On max.wells.edu (24.39.181.217, 10.3.6.111): you each have a directory home/yourname ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 11
Provided by: cshil
Category:
Tags: class | locations | max | office

less

Transcript and Presenter's Notes

Title: CS 330 Class 7


1
CS 330 Class 7
  • Programming plan for Oct 15, 2007
  • start PHP
  • logistics
  • Reading (Williams and Lane)
  • heavy emphasis on string manipulation. Why?
  • picking apart user input, file names, urls
  • use text as you need it
  • Supplement Programming PHP in TA office
  • Reference www.php.net

2
Begin PHP
  • Syntax similar to C
  • Embedded between lt?php ?gt or lt? ?gt
  • .php file extension
  • time.php
  • ltbodygt
  • lt?php echo date("his a", time()) ?gt
  • lt!-- time() is the current time, date formats
    it --gt
  • lt/bodygt
  • lt/htmlgt
  • echo prints to the page

3
More on time()
  • What would this produce ?
  • lt?php echo time() ?gt //(time2.php)
  • The seconds since 1/1/70 GMT
  • Used for time stamping
  • Many functions for converting between this and
    dates
  • Problem stored as 32 bit integer and runs out in
    2038
  • microtime() for generating subseconds

4
Passing Data to the Server
  • Passed with the HTTP header
  • environment variables describing host and
    client environments
  • form variables describing data sent with a form
  • Environment variables stored in the associative
    array
  • _ENV (preferred) or
  • HTTP_ENV_VARS
  • env1.php
  • ltbodygt
  • Server name lt?php echo _ENV'SERVER_NAME'?
    gtltbr /gt
  • Running on port lt?php echo _ENV'SERVER_PORT'?
    gt ltbr /gt
  • Server software lt?php echo _ENV'SERVER_SOFTWARE
    '?gt ltbr /gt
  • Server protocol lt?php echo _ENV'SERVER_PROTOCOL
    '?gt ltbr /gt
  • lt/bodygt
  • env2.php
  • lt?php phpinfo() ?gt //phpinfo is a built-in
    function
  • an array whose subscripts are text

5
  • Restricting Page Access
  • restrict.php
  • lt?php
  • restrict access depending on user domain
  • remoteaddr _ENV'REMOTE_ADDR'
  • if (ereg(remoteaddr, '10\.3/'))
  • header('Location examples.htm')
  • else
  • echo "Access restricted to Wells campus",
    "\n\n"
  • ?gt
  • What do you think ereg is?

6
Server Variables
  • server.php
  • lthtmlgt
  • ltheadgt
  • lttitlegtServer Variableslt/titlegt
  • lt/headgt
  • ltbodygt
  • lt?php
  • foreach (_SERVER as key gtval)
  • echo '_SERVER'. key ." valltbr /gt"
  • ?gt
  • lt/bodygt
  • lt/htmlgt
  • Syntax
  • foreach goes through each element in _SERVER
  • keygtval val is the value associated with
    subscript key
  • 'contents' are literal, "contents" are interpreted

7
Echoing Form Information (Via Get)
  • form1.php (triggered by form1.htm)
  • lthtmlgtltheadgtlttitlegtSimple Form Processinglt/titlegtlt
    /headgt
  • ltbodygt
  • lth2gtSimple Form Processinglt/h2gt
  • lthrgt
  • The query string is 'lt?php echo
    _ENV'QUERY_STRING' ?gt'
  • ltbr /gtltbr /gt
  • Form variable 'Name' has value lt?php echo
    _GET'Name' ?gt
  • ltbr /gtltbr /gt
  • lt?php form split ("",_ENV'QUERY_STRING')
    ?gt
  • The field lt?php echo form'0'?gt
  • ltbr /gt
  • The data lt?php echo form'1' ?gt
  • lthrgt
  • lt/bodygt
  • lt/htmlgt

8
  • Good News if you know the fields, you don't
    need "split"
  • form2.php (from form2.htm)
  • lthtmlgt
  • ltheadgtlttitlegtForm2lt/titlegtlt/headgt
  • ltbodygt
  • lth2gtForm Processing 2lt/h2gt
  • lthrgt
  • The query string is 'lt?php echo
    _ENV'QUERY_STRING' ?gt'ltbr /gt
  • Form variable 'Name' has value 'lt?php echo
    _GET'Name'?gt'ltbr /gt
  • Form variable 'Field' has value 'lt?php echo
    _GET'Field'?gt'
  • lthrgt
  • lt/body
  • lt/htmlgt

9
  • form2p.php (from form2p.htm)
  • lthtmlgt
  • ltheadgtlttitlegtForm 2 Postlt/titlegtlt/headgt
  • ltbodygt
  • lth2gtForm Processing 2, Postlt/h2gt
  • lthrgt
  • Form variable 'Name' has value 'lt?php echo
    _POST'Name'?gt'ltbr /gt
  • Form variable 'Field' has value 'lt?php echo
    _POST'Field'?gt'
  • lthrgt
  • lt/bodygt
  • lt/htmlgt

10
Logistics
  • On your machine download php from
    http//www.php.net/
  • On max.wells.edu (24.39.181.217, 10.3.6.111)
  • you each have a directory home/yourname
  • my files are in /carol/php
  • More Professor Zhu
Write a Comment
User Comments (0)
About PowerShow.com