pset7: C$50 Finance Tommy MacWilliam
Permissions PHP pset7: C$50 Finance Registration
Stock Quotes
Buying Stocks Tommy MacWilliam Selling Stocks
History [email protected] October 30, 2011 Today’s Music
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration I Basshunter
Stock Quotes I Angel in the Night Buying Stocks I Plane to Spain Selling Stocks I Boten Anna History I Ievas Polka Today
pset7: C$50 Finance Tommy MacWilliam
Permissions I permissions PHP I PHP Registration
Stock Quotes I registration
Buying Stocks I stock quotes Selling Stocks I buying stock History I selling stock
I maintaining history public_html
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration I mkdir ~/public_html
Stock Quotes I cd ~/public_html Buying Stocks I git clone Selling Stocks
History http://cdn.cs50.net/2011/fall/psets/7/pset7.git Permissions
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration I chmod: change permissions of file or folder Stock Quotes
Buying Stocks I chmod a+x ~
Selling Stocks I make ~ executable for all users History Permissions
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP I chmod a+x ~ ~/public_html ~/public_html/pset7 Registration I Stock Quotes make home directory executable by everyone
Buying Stocks I chmod a+r css/* images/* Selling Stocks I make all CSS and image files readable by everyone History I can’t execute an image as a program! Permissions
pset7: C$50 Finance Tommy MacWilliam
Permissions I chmod 644 file PHP
Registration rwx 111 7
Stock Quotes rw 110 6 rx 101 5 Buying Stocks I r 100 4 Selling Stocks wx 011 3 History w 010 2 x 001 1 Permissions Cheat Sheet
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration I folders: chmod 711 folder
Stock Quotes I image, HTML, CSS, and Javascript files: chmod 644 Buying Stocks logo.png Selling Stocks
History I PHP files: chmod 600 file.php Home Page
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP I create new index.html Registration I don’t forget to chmod 644 index.html Stock Quotes Buying Stocks I make it pretty! Selling Stocks I visit http://localhost/~jharvard History I validate HTML with http://validator.w3c.org PHP in 10 Seconds
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration I files end in .php Stock Quotes I code enclosed between Buying Stocks I variables start with $ Selling Stocks
History I variables are weakly typed PHP in 10 Seconds
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration
Stock Quotes
Buying Stocks
Selling Stocks
History Distro Code
pset7: C$50 Finance Tommy MacWilliam
Permissions I index.php: homepage PHP I common.php: code run before each page loads Registration
Stock Quotes I constants.php: database information
Buying Stocks I helpers.php: helpful functions like lookup() Selling Stocks I stock.php: definition of Stock struct History I login.php: display login form
I login2.php: process login login2.php
pset7: C$50 Finance Tommy MacWilliam
Permissions PHP I get username and password from $_POST Registration I look up user from database based on username Stock Quotes I compare hash of inputted password to hash of Buying Stocks
Selling Stocks password in database
History I if matching, remember the ID of the user in $_SESSION I $_SESSION data persists across pages SELECT
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP Registration I SELECT * FROM users WHERE username = "malan" Stock Quotes I get the data from every column Buying Stocks I in a table called users Selling Stocks I only if the username column has the value malan History Conditions
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP I SELECT * FROM users WHERE username = "malan" OR Registration cash < 9000 Stock Quotes Buying Stocks I SELECT username, hash FROM users WHERE username Selling Stocks != "malan" History I SELECT COUNT(*) FROM users WHERE cash > 9000 Using SQL
pset7: C$50 Finance Tommy MacWilliam I mysql_connect(DB_SERVER, DB_USERNAME, Permissions DB_PASSWORD): connect to database PHP Registration I mysql_select_db(DB_NAME): specify database to Stock Quotes operate within Buying Stocks I $query = "SELECT * FROM users": create database Selling Stocks query History I $result = mysql_query($query): run database query
I $row = mysql_fetch_array($result): convert result to PHP associative array, one row at a time TODO
pset7: C$50 Finance Tommy MacWilliam
Permissions
PHP
Registration 1. display form Stock Quotes 2. check if passwords match Buying Stocks 3. check if username already exists Selling Stocks
History 4. add row to database
Forms
pset7: C$50 Finance Tommy MacWilliam
Permissions I cp login.php register.php PHP I