introductionto php

Download Introductionto Php

If you can't read please download the document

Upload: andres-maneiro

Post on 16-Apr-2017

4.241 views

Category:

Business


0 download

TRANSCRIPT

Introduction to PHP scripting language

Lorenzo Tilve lvaro

List of topics

Basic concepts

Apache/CGI mode vs CLI

Installation & Configuration

Syntax

Web development with PHP

Security

Practices index

Basic concepts

PHP ( PHP Hypertext Preprocessor ) was born in 1994

Reference documentation

http://www.php.net

http://www.php.net/manual/en/langref.php

Characteristics:

Interpreted language

Implicit variable declaration

PHP stack

Basic concepts

Main advantages:

Lightweight

Ease of use and administration

Multiple library support

Fast learning curve

Multiplatform

Provides a lot of connectors

Basic concepts

Some disadvantages:

Complexity to handle large session data

Upgrade problems:

Issues with backwards compatibility

Certain package dependences

Lack of debugging tools

Handling of balance load

Basic concepts

Current releases state (Feb 08):

Stable branch 5.2.5

Compatibility support 4.4.8

Migration information

www.php.net/manual/en/migration5.php

Road to PHP 6

Apache/CGI mode vs CLI

PHP as a scripting language

Embed integration with HTML and use of templates

Programmed scripting process via cronjobs

Separated configuration files for different scenarios

Apache/CGI mode vs CLI

In CGI mode all PHP stack is regenerated with each request

Necessity of usage of GET, POST and SESSION variables to communication between requests

Cookie and user agent management

Alternatives for other technological components integration

Installation & Configuration

PHP multiplatform packages

Bundled packages of Apache+Mysql+PHP environment

For Ubuntu / Debian distributions

apt-get install php5 php5-common php5-cli

Specific compilation instructions

http://es.php.net/manual/en/install.unix.php

Configuration

Other important libraries:

php5-imap: IMAP module for php5

php5-ldap: LDAP module for php5

php5-mcrypt: MCRYPT module for php5

php5-mysql: MySQL module for php5

php5-gd: GD module for php5

php5-pear: PEAR - PHP Extension and Application

...

PHP accelerator

Zend extension

Configuration

Configuration files

/etc/php5/cli/etc.ini

/etc/php5/apache2/etc.ini

/etc/php5/cgi/etc.ini

For Apache usage

Apache configuration and virtualhosts setup with php_value directives

Configuration

Important configuration settings in php.ini:

safe_mode configuration

max_execution_time & memory_limit

register_globals

logging directories

Syntax

PHP code structure

Basic syntax

Types, variables and Constants

Expressions

Operators

Control Structures

Functions

Syntax

Basic syntax

PHP script

HTML embed

Syntax

Types, variables and Constants

// Constat declaration

define( "STRING_MAX_LENGTH", 25);

define( "USER", 1 );

define( "USER_GROUP", 2 );

define( "STANDARD_USER", "user" );

define( "ADMIN_USER", "admin" );

Syntax

Types, variables and Constants

// Arrays

$array = array( 'item1', 'item2', 'item3' );

$array2 = array( 'u1'=>'item1', 'u2'=>'item2' );

$arra2['u3'] = 'item3';

// Strings

$string = 'This is a string';

$string2 = "This is another string and $string";

$string3 = $string . " and " . $string2;

Syntax

Conditions

$user_id = 'login';

$ban_list = array( ) ;

// && and, || or, == equal operators

if ( empty( $user_id ) || in_array( $user_$ban_list ) )

{

exit( );

}

Syntax

Looping

$elements = array( one, two, three);

// Foreach, while and for loops

foreach ( $elements as $value ) {

$results[ ] = $value. "processed";

}

Syntax

Functions

// File requirements and inclussions

require_once(myclass.php);

include_once(myclass.php);

// Declaration

function foo ( $param1, $param2 = def_value, ...) {

// do some stuff

return $value;

}

Security

Safe mode

Limits execution of server-owned scriptsa and safe_mode_include_dir binaries

Register globals

Server validation

Unsafe client-side validation ( Javascript )

Filter SQL-injections

$id = mysql_real_escape_string($_POST['input']);

$SQL = 'SELECT * FROM table WHERE id = ' . $id;

Web development

PHP is extremely popular for CMS development on LAMP environments.

Typo3, eZPublish, Joomla, Drupal, phpNuke, Mambo, ...

www.cmsmatrix.com

Original web approach vs. specific PHP pages with presentation templates:

ModelViewController design pattern

Web development

Processing HTTP variables

Cookies and session handling

Connector for system integration

Web services using nusoap

Database handling

Image management

LDAP, Mail, etc, ...

Practices

Introductory practices

Basic PHP syntax and CLI mode

Configuration and security

Database and filesystem interaction

Data processing and sending mail

Teachers

Lorenzo Tilve. Igalia

Engineering group.

[email protected]

Xavier Castao. Igalia

Engineering group.

[email protected]

Pulse para editar el formato del texto de ttulo

Pulse para editar los formatos del texto del esquema

Segundo nivel del esquema

Tercer nivel del esquema

Cuarto nivel del esquema

Quinto nivel del esquema

Sexto nivel del esquema

Sptimo nivel del esquema

Octavo nivel del esquema

Noveno nivel del esquema

Master on Free Software