Geek Austin PHP Class - Session 3

13
Beginning PHP Session #3 November 30, 2010 Josh Butts

description

 

Transcript of Geek Austin PHP Class - Session 3

Page 1: Geek Austin PHP Class - Session 3

Beginning PHPSession #3

November 30, 2010

Josh Butts

Page 2: Geek Austin PHP Class - Session 3

Agenda

•Application organization

•Superglobals

•Forms, GET and POST

•Sessions

•Basic Dates & Times

Page 3: Geek Austin PHP Class - Session 3

Superglobals

•Available in every scope, no matter what

•Automatically set by PHP

•Arrays

•#1 attack vector

Page 4: Geek Austin PHP Class - Session 3

$_GET

•Associative array corresponding to the query string

•Use this for READ ONLY data

Page 5: Geek Austin PHP Class - Session 3

$_POST

•Associative array that corresponds to form POSTs

•Use this when you will be modifying something on the server

•Array keys correspond to HTML input names

Page 6: Geek Austin PHP Class - Session 3

$_POST

Page 7: Geek Austin PHP Class - Session 3

$_SERVER

•Contains environment information

•Contains information about the HTTP request used to access this page

Page 8: Geek Austin PHP Class - Session 3

Sessions

•Keep track of info about your user

•Each user gets an ID and a cookie

•Actual session data is stored on the server

•Low security but easy

Page 9: Geek Austin PHP Class - Session 3

Using Sessions

•Call session_start()

•Use $_SESSION superglobal to get and set data

•Sessions expire when the browser is closed (you can configure this)

Page 10: Geek Austin PHP Class - Session 3

Session Demo

Page 11: Geek Austin PHP Class - Session 3

Dates & Times•Dates & times are relative to the

timezone of your server

•time() - Unix Timestamp

•date() - format a date string

•mktime() - get a specific unix timestamp

•strtotime() - convert an english-ish string to a timestamp

Page 12: Geek Austin PHP Class - Session 3

extract()

•Registers all the keys in an array as variables

•Use extreme with caution

Page 13: Geek Austin PHP Class - Session 3

Let’s buildsomething real