Your SlideShare is downloading. ×
0
Introduction to PHP scripting language Lorenzo Tilve Álvaro
List of topics <ul><li>Basic concepts </li></ul><ul><li>Apache/CGI mode vs CLI </li></ul><ul><li>Installation & Configurat...
Basic concepts <ul><li>PHP ( PHP Hypertext Preprocessor ) was born in 1994 </li></ul><ul><li>Reference documentation </li>...
Basic concepts <ul><li>Main advantages: </li></ul><ul><ul><li>Lightweight </li></ul></ul><ul><ul><li>Ease of use and admin...
Basic concepts <ul><li>Some disadvantages: </li></ul><ul><ul><li>Complexity to handle large session data </li></ul></ul><u...
Basic concepts <ul><li>Current releases state (Feb 08): </li></ul><ul><ul><li>Stable branch 5.2.5 </li></ul></ul><ul><ul><...
Apache/CGI mode vs CLI <ul><li>PHP as a scripting language </li></ul><ul><li>Embed integration with HTML and use of templa...
Apache/CGI mode vs CLI <ul><li>In CGI mode all PHP stack is regenerated with each request </li></ul><ul><ul><li>Necessity ...
Installation & Configuration <ul><li>PHP multiplatform packages </li></ul><ul><ul><li>Bundled packages of Apache+Mysql+PHP...
Configuration <ul><li>Other important libraries: </li></ul><ul><ul><ul><li>php5-imap: IMAP module for php5 </li></ul></ul>...
Configuration <ul><li>Configuration files </li></ul><ul><ul><li>/etc/php5/cli/etc.ini </li></ul></ul><ul><ul><li>/etc/php5...
Configuration <ul><li>Important configuration settings in  php.ini : </li></ul><ul><ul><ul><li>safe_mode configuration </l...
Syntax <ul><li>PHP code structure </li></ul><ul><ul><li>Basic syntax </li></ul></ul><ul><ul><li>Types, variables and Const...
Syntax <ul><li>Basic syntax </li></ul><ul><ul><li>PHP script </li></ul></ul><ul><ul><ul><li><?php  </li></ul></ul></ul><ul...
Syntax <ul><li>Types, variables and Constants </li></ul><ul><ul><ul><li>// Constat declaration </li></ul></ul></ul><ul><ul...
Syntax <ul><li>Types, variables and Constants </li></ul><ul><ul><ul><li>// Arrays </li></ul></ul></ul><ul><ul><ul><li>$arr...
Syntax <ul><li>Conditions </li></ul><ul><ul><ul><li>$user_id = 'login'; </li></ul></ul></ul><ul><ul><ul><li>$ban_list = ar...
Syntax <ul><li>Looping </li></ul><ul><ul><ul><li>$elements = array( “one”, “two”, “three”); </li></ul></ul></ul><ul><ul><u...
Syntax <ul><li>Functions </li></ul><ul><ul><ul><li>// File requirements and inclussions </li></ul></ul></ul><ul><ul><ul><l...
Security <ul><li>Safe mode </li></ul><ul><ul><li>Limits execution of server-owned scriptsa and safe_mode_include_dir binar...
Web development <ul><li>PHP is extremely popular for CMS development on LAMP environments. </li></ul><ul><ul><li>Typo3, eZ...
Web development <ul><li>Processing HTTP variables </li></ul><ul><ul><li>Cookies and session handling </li></ul></ul><ul><l...
Practices <ul><li>Introductory practices </li></ul><ul><ul><li>Basic PHP syntax and CLI mode </li></ul></ul><ul><ul><li>Co...
Teachers <ul><li>Lorenzo Tilve. Igalia </li></ul><ul><ul><li>Engineering group. </li></ul></ul><ul><ul><li>[email_address]...
Upcoming SlideShare
Loading in...5
×

Introductionto Php

3,917

Published on

Published in: Business, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,917
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
164
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Introductionto Php"

  1. 1. Introduction to PHP scripting language Lorenzo Tilve Álvaro
  2. 2. List of topics <ul><li>Basic concepts </li></ul><ul><li>Apache/CGI mode vs CLI </li></ul><ul><li>Installation & Configuration </li></ul><ul><li>Syntax </li></ul><ul><li>Web development with PHP </li></ul><ul><li>Security </li></ul><ul><li>Practices index </li></ul>
  3. 3. Basic concepts <ul><li>PHP ( PHP Hypertext Preprocessor ) was born in 1994 </li></ul><ul><li>Reference documentation </li></ul><ul><ul><li>http://www.php.net </li></ul></ul><ul><ul><li>http://www.php.net/manual/en/langref.php </li></ul></ul><ul><li>Characteristics: </li></ul><ul><ul><li>Interpreted language </li></ul></ul><ul><ul><li>Implicit variable declaration </li></ul></ul><ul><ul><li>PHP stack </li></ul></ul>
  4. 4. Basic concepts <ul><li>Main advantages: </li></ul><ul><ul><li>Lightweight </li></ul></ul><ul><ul><li>Ease of use and administration </li></ul></ul><ul><ul><li>Multiple library support </li></ul></ul><ul><ul><li>Fast learning curve </li></ul></ul><ul><ul><li>Multiplatform </li></ul></ul><ul><ul><li>Provides a lot of connectors </li></ul></ul>
  5. 5. Basic concepts <ul><li>Some disadvantages: </li></ul><ul><ul><li>Complexity to handle large session data </li></ul></ul><ul><ul><li>Upgrade problems: </li></ul></ul><ul><ul><ul><li>Issues with backwards compatibility </li></ul></ul></ul><ul><ul><ul><li>Certain package dependences </li></ul></ul></ul><ul><ul><li>Lack of debugging tools </li></ul></ul><ul><ul><li>Handling of balance load </li></ul></ul>
  6. 6. Basic concepts <ul><li>Current releases state (Feb 08): </li></ul><ul><ul><li>Stable branch 5.2.5 </li></ul></ul><ul><ul><li>Compatibility support 4.4.8 </li></ul></ul><ul><li>Migration information </li></ul><ul><ul><li>www.php.net/manual/en/migration5.php </li></ul></ul><ul><li>Road to PHP 6 </li></ul>
  7. 7. Apache/CGI mode vs CLI <ul><li>PHP as a scripting language </li></ul><ul><li>Embed integration with HTML and use of templates </li></ul><ul><li>Programmed scripting process via cronjobs </li></ul><ul><li>Separated configuration files for different scenarios </li></ul>
  8. 8. Apache/CGI mode vs CLI <ul><li>In CGI mode all PHP stack is regenerated with each request </li></ul><ul><ul><li>Necessity of usage of GET, POST and SESSION variables to communication between requests </li></ul></ul><ul><ul><li>Cookie and user agent management </li></ul></ul><ul><ul><li>Alternatives for other technological components integration </li></ul></ul>
  9. 9. Installation & Configuration <ul><li>PHP multiplatform packages </li></ul><ul><ul><li>Bundled packages of Apache+Mysql+PHP environment </li></ul></ul><ul><ul><li>For Ubuntu / Debian distributions </li></ul></ul><ul><ul><ul><li>apt-get install php5 php5-common php5-cli </li></ul></ul></ul><ul><li>Specific compilation instructions </li></ul><ul><ul><li>http://es.php.net/manual/en/install.unix.php </li></ul></ul>
  10. 10. Configuration <ul><li>Other important libraries: </li></ul><ul><ul><ul><li>php5-imap: IMAP module for php5 </li></ul></ul></ul><ul><ul><ul><li>php5-ldap: LDAP module for php5 </li></ul></ul></ul><ul><ul><ul><li>php5-mcrypt: MCRYPT module for php5 </li></ul></ul></ul><ul><ul><ul><li>php5-mysql: MySQL module for php5 </li></ul></ul></ul><ul><ul><ul><li>php5-gd: GD module for php5 </li></ul></ul></ul><ul><ul><ul><li>php5-pear: PEAR - PHP Extension and Application </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><li>PHP accelerator </li></ul><ul><ul><li>Zend extension </li></ul></ul>
  11. 11. Configuration <ul><li>Configuration files </li></ul><ul><ul><li>/etc/php5/cli/etc.ini </li></ul></ul><ul><ul><li>/etc/php5/apache2/etc.ini </li></ul></ul><ul><ul><li>/etc/php5/cgi/etc.ini </li></ul></ul><ul><li>For Apache usage </li></ul><ul><ul><li>Apache configuration and virtualhosts setup with php_value directives </li></ul></ul>
  12. 12. Configuration <ul><li>Important configuration settings in php.ini : </li></ul><ul><ul><ul><li>safe_mode configuration </li></ul></ul></ul><ul><ul><ul><li>max_execution_time & memory_limit </li></ul></ul></ul><ul><ul><ul><li>register_globals </li></ul></ul></ul><ul><ul><ul><li>logging directories </li></ul></ul></ul>
  13. 13. Syntax <ul><li>PHP code structure </li></ul><ul><ul><li>Basic syntax </li></ul></ul><ul><ul><li>Types, variables and Constants </li></ul></ul><ul><ul><li>Expressions </li></ul></ul><ul><ul><li>Operators </li></ul></ul><ul><ul><li>Control Structures </li></ul></ul><ul><ul><li>Functions </li></ul></ul>
  14. 14. Syntax <ul><li>Basic syntax </li></ul><ul><ul><li>PHP script </li></ul></ul><ul><ul><ul><li><?php </li></ul></ul></ul><ul><ul><ul><li>echo “This is a php file: ”; </li></ul></ul></ul><ul><ul><ul><li>// Online comment </li></ul></ul></ul><ul><ul><ul><li>?> </li></ul></ul></ul><ul><ul><li>HTML embed </li></ul></ul><ul><ul><ul><li><body> </li></ul></ul></ul><ul><ul><ul><li><? phpinfo(); /* This is a comment */ ?> </li></ul></ul></ul><ul><ul><ul><li></body> </li></ul></ul></ul>
  15. 15. Syntax <ul><li>Types, variables and Constants </li></ul><ul><ul><ul><li>// Constat declaration </li></ul></ul></ul><ul><ul><ul><li>define( &quot;STRING_MAX_LENGTH&quot;, 25); </li></ul></ul></ul><ul><ul><ul><li>define( &quot;USER&quot;, 1 ); </li></ul></ul></ul><ul><ul><ul><li>define( &quot;USER_GROUP&quot;, 2 ); </li></ul></ul></ul><ul><ul><ul><li>define( &quot;STANDARD_USER&quot;, &quot;user&quot; ); </li></ul></ul></ul><ul><ul><ul><li>define( &quot;ADMIN_USER&quot;, &quot;admin&quot; ); </li></ul></ul></ul>
  16. 16. Syntax <ul><li>Types, variables and Constants </li></ul><ul><ul><ul><li>// Arrays </li></ul></ul></ul><ul><ul><ul><li>$array = array( 'item1', 'item2', 'item3' ); </li></ul></ul></ul><ul><ul><ul><li>$array2 = array( 'u1'=>'item1', 'u2'=>'item2' ); </li></ul></ul></ul><ul><ul><ul><li>$arra2['u3'] = 'item3'; </li></ul></ul></ul><ul><ul><ul><li>// Strings </li></ul></ul></ul><ul><ul><ul><li>$string = 'This is a string'; </li></ul></ul></ul><ul><ul><ul><li>$string2 = &quot;This is another string and $string&quot;; </li></ul></ul></ul><ul><ul><ul><li>$string3 = $string . &quot; and &quot; . $string2; </li></ul></ul></ul>
  17. 17. Syntax <ul><li>Conditions </li></ul><ul><ul><ul><li>$user_id = 'login'; </li></ul></ul></ul><ul><ul><ul><li>$ban_list = array( ) ; </li></ul></ul></ul><ul><ul><ul><li>// && and, || or, == equal operators </li></ul></ul></ul><ul><ul><ul><li>if ( empty( $user_id ) || in_array( $user_$ban_list ) ) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>exit( ); </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  18. 18. Syntax <ul><li>Looping </li></ul><ul><ul><ul><li>$elements = array( “one”, “two”, “three”); </li></ul></ul></ul><ul><ul><ul><li>// Foreach, while and for loops </li></ul></ul></ul><ul><ul><ul><li>foreach ( $elements as $value ) { </li></ul></ul></ul><ul><ul><ul><li>$results[ ] = $value. &quot;processed&quot;; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  19. 19. Syntax <ul><li>Functions </li></ul><ul><ul><ul><li>// File requirements and inclussions </li></ul></ul></ul><ul><ul><ul><li>require_once(“myclass.php”); </li></ul></ul></ul><ul><ul><ul><li>include_once(“myclass.php”); </li></ul></ul></ul><ul><ul><ul><li>// Declaration </li></ul></ul></ul><ul><ul><ul><li>function foo ( $param1, $param2 = def_value, ...) { </li></ul></ul></ul><ul><ul><ul><li>// do some stuff </li></ul></ul></ul><ul><ul><ul><li>return $value; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  20. 20. Security <ul><li>Safe mode </li></ul><ul><ul><li>Limits execution of server-owned scriptsa and safe_mode_include_dir binaries </li></ul></ul><ul><li>Register globals </li></ul><ul><li>Server validation </li></ul><ul><ul><li>Unsafe client-side validation ( Javascript ) </li></ul></ul><ul><ul><li>Filter SQL-injections </li></ul></ul><ul><ul><ul><li>$id = mysql_real_escape_string($_POST['input']); </li></ul></ul></ul><ul><ul><ul><li>$SQL = 'SELECT * FROM table WHERE id = ' . $id; </li></ul></ul></ul>
  21. 21. Web development <ul><li>PHP is extremely popular for CMS development on LAMP environments. </li></ul><ul><ul><li>Typo3, eZPublish, Joomla, Drupal, phpNuke, Mambo, ... </li></ul></ul><ul><ul><li>www.cmsmatrix.com </li></ul></ul><ul><li>Original web approach vs. specific PHP pages with presentation templates: </li></ul><ul><ul><li>Model–View–Controller design pattern </li></ul></ul>
  22. 22. Web development <ul><li>Processing HTTP variables </li></ul><ul><ul><li>Cookies and session handling </li></ul></ul><ul><li>Connector for system integration </li></ul><ul><ul><li>Web services using nusoap </li></ul></ul><ul><ul><li>Database handling </li></ul></ul><ul><ul><li>Image management </li></ul></ul><ul><ul><li>LDAP, Mail, etc, ... </li></ul></ul>
  23. 23. Practices <ul><li>Introductory practices </li></ul><ul><ul><li>Basic PHP syntax and CLI mode </li></ul></ul><ul><ul><li>Configuration and security </li></ul></ul><ul><ul><li>Database and filesystem interaction </li></ul></ul><ul><ul><li>Data processing and sending mail </li></ul></ul>
  24. 24. Teachers <ul><li>Lorenzo Tilve. Igalia </li></ul><ul><ul><li>Engineering group. </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul><ul><li>Xavier Castaño. Igalia </li></ul><ul><ul><li>Engineering group. </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×