php, databases, and cookies dave pease ids496 12/2/2003

11
PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003 www.dpease.com/php

Upload: asher-clark

Post on 21-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

PHP, Databases, and CookiesDave Pease

IDS496

12/2/2003

www.dpease.com/php

Page 2: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

PHP Basics Scripting language

Non-compiled Similar in operation to Perl Similar in syntax to C Designed for the Web Releases exist for all major operating systems and

HTTP servers MS Windows/MS IIS, Linux/Apache, etc.

Page 3: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

PHP Syntax Server executes anything

between <?php ?> as PHP code

# or // for comments Lines end in semi-colons; Generally all files with .php

extensions are executed Can be changed in HTTP server

configurations

Page 4: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

PHP and HTML PHP can be embedded in HTML

Anything outside <?php ?> is ignored by PHP but rendered by HTTP server as normal

Page 5: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Passing Arguments to PHP PHP can read command line arguments

No argument arg=foo

Page 6: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

PHP and Forms PHP can read data from HTML forms

•Check functions can be easily implemented

•Select boxes in forms can be populated in loops in PHP

•HTML page content always displays

•Utilize PHP’s helpful environmental variables

Page 7: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Databases and PHP For content-heavy (article based) websites, PHP with

a database back-end is an excellent solution Very few scripts and pages to maintain Easy to change features/colors/layout across entire site

quickly

Database(many articles)

Single PHP pageSite visitor

Page 8: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Database types MySQL

Popular, many users, lots of documentation, excellent integration with PHP

MyPHPAdmin is a popular, free tool that allows you to administer your MySQL database via the web

PostgreSQL Newer, more features, smaller user base

Both databases: Are free Support SQL instruction set (IDS 480)

Page 9: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Cookies Information a website can

write to a client Client must have cookies

enabled in their browser Many legitimate uses

A site can only read a cookie that it put on the client’s computer, so allowing cookies won’t throw your entire hard drive open to unscrupulous websites to invade

PHP has built-in support for cookies

Page 10: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Cookie Example: sessiontoken When a user visits a site, PHP script checks for

cookie If it exists, get unique sessiontoken from cookie to check

login status in database If it doesn’t exist, create cookie with new sessiontoken

and create new row in database Script “included” in every PHP page in site

Regular visitors/site members stay “logged in” and don’t have to re-enter their passwords

Page 11: PHP, Databases, and Cookies Dave Pease IDS496 12/2/2003

Resources php.net

Every PHP function documented experts-exchange.com

Good place to get answers to tough PHP/database questions

google.com Describe what you are trying to do

and include the string “PHP” and you will nearly always find the answer documented somewhere on the internet

postgresql.com PostgreSQL database

documentation

mysql.com MySQL database documentation

phpmyadmin.net Administrate a MySQL database

via the web oreilly.com

Excellent technical books editplus.com

Notepad replacement/script editor; shareware

http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY free terminal utility