300 likes | 373 Views
PHP HyPertext : Preprocessor. By: Justin T. Pleva. What is PHP?. General purpose Server-side web development Console application. Background. First created in 1994 by Rasmus Lerdorf Designed to streamline web tasks Designed to access databases for storing data. Used for web forms
E N D
PHP HyPertext: Preprocessor By: Justin T. Pleva
What is PHP? • General purpose • Server-side web development • Console application
Background • First created in 1994 by RasmusLerdorf • Designed to streamline web tasks • Designed to access databases for storing data. • Used for web forms • First public release in 1995
Background • Used primarily as website scripting • Text Interpreter/filter • Installed on over 20 million websites and domains • Can install multiple versions • Current version 5.4 • Object-Oriented
History • Originally named “Personal Homepage Tools” • Rewritten in 1997 using C, released publicly • Renamed to “Hypertext Preprocessor” • Version 4 introduced command line functionality • Version 5 rewrote Object support • Version 6 has been postponed
Licensing • Open source • PHP License • Term “PHP” cannot be used directly in a project.
Operating Environments • Windows • Mac • Linux • Almost any others • Built from source • Web servers • Apache • IIS • Lighttpd
Stacks • Comes bundled with many Linux Distributions • Bundles for • Mac: MAMP (Mac, Apache, MySQL, PHP) • Linux: LAMP (Linux, Apache, MySQL, PHP) • Windows: WAMP …
How it works • Client Request sent to Web server • Web server directs to PHP filter • PHP processes data and sends to web server • Web server sends back to client
Syntax • Similar to major programming languages • C • Java • Can be embedded inside other languages such as HTML
Syntax : Declarations • Declared PHP code with delimiters • <?php … ?> • <? … ?> • <script language=”php”> </script> • ASP Style • <% … %> • Code is only executed between these delimiters
Syntax: Variables • Loosely typed, unlike C/Java // Create an integer and set equal to 3 $myVariable = 3; Prefixed name with ‘$’ Notice no type specified, this can be a string value of “3”, character ‘3’ or integer value of 3. Depends upon notation! Need to be careful with variable types!
Syntax: Commenting • Similar to other langues • // This is a single line comment • /* This is a block style comment */
Syntax: Functions • Functions declarations similar to C/Java Function myFunction($value1, $value2) { return $value1 + $value2; } Can be value returning or not!
Syntax: Loops • Similar to C/Java • For … While … Do While … for each $i = 0; While ( $i != 5 ) { echo “Number is: “ . $i . “<br />; $i++; } Notice the ‘.’!
Syntax: File handling • Can Open and write to file system • Used to read/write from a server for web content • Built in file support for: • XML • FTP • Zip • Cookies
Syntax: Get/Post • Can get data using $_Get[“ “] • Useful for retrieving data from url. • Can send data using $_Post[“ “] • Useful for submitting user forms such as request information forms.
Syntax: Objects • PHP is Object-Oriented • Can create classes and objects of any type • Similar to C/Java • Can have private/public methods and data members • Arrow notation instead of dot notation
Syntax: Mail • Built in Email support • Create text based email • Send via 1 function.
File Extensions • Standard extension: .php • Can have others • .phtml • .php5 • If multiple versions are installed, .php5 will refer to version 5 installed
Usage • Command line • Dynamic websites • Content Management • Can be used for Desktop applications • GUI controls
Database Support • Built to work primarily with MySQL • Capable of working with others: • MS SQL • Oracle • Postgres • PDO Driver
Security • Very little security holes have been found with core PHP application • Security risks come from each individual programmer, not the PHP filter! • Bad programming habits
Web Presence • 20 Million domains/websites • Comes pre installed with many Linux distributions. • Content Management Systems
Web Presence: CMS • Many Content Management Systems are built with PHP • Joomla • Wordpress • Drupal • Far more built with PHP than others such as .Net
Community Support • Need help? Google it. • Since PHP is so widely used, there is great community support • Content Management Systems are sometimes community built
Script availability • Community Support • Open Source • http://www.hotscripts.com
Development • Code in Notepad • IDE Support • Netbeans • Zend Studio • Eclipse • Codelobster
Conclusion • General Scripting lanaguage • Over 20 million domains • Command line/Web server-side • Various database support • Thousands of pre-built scripts • Open source