140 likes | 276 Views
PHP Training. Senior Design team Ongo8 Sunday October 16, 2005. Development Environment 1/2. Download WinSCP: ongo8.ece.iastate.edu/ongo8/phptraining/winscp.exe Start WinSCP Host name: ongo8.ece.iastate.edu Ask leader for username and password
E N D
PHP Training Senior Design team Ongo8 Sunday October 16, 2005
Development Environment 1/2 • Download WinSCP: ongo8.ece.iastate.edu/ongo8/phptraining/winscp.exe • Start WinSCP • Host name: ongo8.ece.iastate.edu • Ask leader for username and password • Directories -> Remote directory: /var/www/html/ongo8/phptraining • Drag and drop both PHP files to desktop
Development Environment 2/2 • Go up a folder to “ongo8” and enter into your group’s directory, then into your personal directory • If you don’t have a personal directory, go to: Commands->Create Directory… and make yourself one • Drag both php files from your desktop into your personal directory • Double click on the file “simple.php”
Syntax • General syntax: • Code is enclosed in <?php and ?> tags. • Like C, Java, Perl, etc., each instruction ends with a semicolon • PHP supports C, C++ and shell style comments. • /* multi-line comment */ • # shell one line comment • // one line C++ comment • NOTE: one line comments refer to the end of the line (\n character) or end of PHP instruction (;) whichever comes first
Basic PHP • Your first PHP enabled web page!! • Add the following code somewhere: • echo "<p>Hello World</p>"; • Open the web page in your browser: ongo8.ece.iastate.edu/ongo8/group/username/simple.php • Now add this: • phpinfo(); • Open the web page again
Variables • Four scalar variables: boolean, integer, float, string • Two compounds: array, object • Variables start with a “$” • Use var_dump(); to see type and value of a certain variable. Very useful for debugging!! • Example code: $bool = TRUE; // a boolean $str = "foo"; // a string $int = 12; // an integer var_dump();
Flow Control • If/else/elseif statements are used just like in C if (condition) { // …do this if true..; } else { //do this otherwise } • switch, for, while, etc. statements are just like in C too
Arrays //Declare an empty array $errors = array(); //Add values to the array $errors[] = ‘this goes in index 0’; $errors[] = ‘this goes in index 1’; $errors[‘err15’] = ‘this goes in index err15’; //Print those values echo "<p>index 0: " . $errors[0] . " <br>"; echo "index err15: " . $errors['err15'] . " <br>"; //Declare an array with pre-defined entries $teachers = array('John'=>’Lamont’, ‘Pat’=>’Patterson’); //Print the array print_r();
Includes • Includes are similar to C: include 'lib.authentication.php'; • Will basically paste the contents of lib.authentication.php wherever the include statement is • Also can use: • include_once • require • require_once
Objects • PHP has very limited support for objects (at least for the version of PHP we’re using) • Can have both constructors and methods • Has no understanding of Public, Private, etc. • Calling the constructor: $userData = new User($fname, $mname, $lname, $notes, $owner, $permission, $username, $password, $passwordh, $startdate, $stopdate, $studentid, $email); • Calling a method: $permission = $userData->getPermission();
Tips and Tricks • Use the php.net documentation, it’s very useful and convenient • Use google • Ask around if you have a question • Don’t use an HTML editor, it messes up PHP code in some people’s experience • Most secure ftp clients let you edit remote files in a local text editor. I use WinSCP.
New Stuff • Authentication (You don’t have to worry about this.) • Quiz timing (Javascript and PHP)