1 / 13

PHP Training

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

dirk
Download Presentation

PHP Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Training Senior Design team Ongo8 Sunday October 16, 2005

  2. 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

  3. 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”

  4. 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

  5. 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

  6. 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();

  7. 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

  8. 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();

  9. 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

  10. 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();

  11. 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.

  12. New Stuff • Authentication (You don’t have to worry about this.) • Quiz timing (Javascript and PHP)

  13. Questions & Comments??

More Related