Form processing in PHP

Tiempo: 2h Form processing in PHP Departamento de Lenguajes y Sistemas Informáticos Software Engineering Group November 2009 [Ángel US V7] Diseño:

4 downloads 165 Views 4MB Size

Recommend Stories


A Practical Course in Terminology Processing
UNIVERSIDAD VERACRUZANA FACULTAD DE IDIOMAS TRABAJO PRACTICO EDUCATIVO "What is terminology?" (first part) Del Libro A Practical Course in Terminol

PROGRAMADOR PHP PARA MÁLAGA CAPITAL
PROGRAMADOR PHP PARA MÁLAGA CAPITAL. Código del anuncio OM\2014\002237 Nombre del anuncio PROGRAMADOR PHP PARA MÁLAGA CAPITAL. Descripción del anu

Orientación a objetos en PHP
Orientación a objetos en PHP Dídac Gil de la Iglesia PID_00155710 CC-BY • PID_00155710 Los textos e imágenes publicados en esta obra están sujetos

Story Transcript

Tiempo: 2h

Form processing in PHP

Departamento de Lenguajes y Sistemas Informáticos

Software Engineering Group November 2009

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Versión original: Jose Antonio Parejo y Pablo Fernandez (noviembre 2008)

escuela técnica superior de ingeniería informática

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

Useful predefined variables Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos

• General – $GLOBALS ≡ Global variables – $_SERVER ≡ Web server information / configuration – $_SESSION ≡ Session data

3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP

• Form Processing – $_REQUEST ≡ User request (usually with form data) – $_FILES ≡ User file sent by form

4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

1

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

$GLOBALS Variable Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP

• Global variables can be used in any PHP section. • $GLOBALS features: – It is an associative array containing all the global variables defined.

– Its format is as following: $GLOBALS[“variable name”] = “value”

• Usage example:

4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION



Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

2

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

$_SERVER Variable Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control

• It contains the server and execution environment information (such as headers, paths, and script locations). •

The entries in this array are created by the web server.

• Some of the information it contains:

6. Clases y objetos

– 'PHP_SELF‟: The filename of the currently executing script.

7. Clases predefinidas

– „SERVER_ADDR‟: The IP address of the server under which the current script is executing.

3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

– „SERVER_NAME‟: The name of the server host under which the current script is executing. – „ SERVER_PORT‟: The port on the server machine being used by the web server for communication.

– „REQUEST_METHOD‟: Which request method was used to access the page; i.e. 'GET', 'POST', … – „REMOTE_ADDR‟: The IP address from which the user is viewing the current page.

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

3

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

$_REQUEST Variable Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP

• It is an associative array that contains the contents of $_GET or $_POST. It is normally used to get the form data sent by user.

1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

• Usage example

4

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

$_FILES Variable Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

• An associative array of items uploaded to the current script via the HTTP POST method. • Its format is as following: $_FILES[“file name”] = FILE_INFO Where FILE_INFO its also an associative array containing: name: The original name of the file on the client machine. type: The mime type of the file (such as "image/gif“) size: The size, in bytes, of the uploaded file. tmp_name: The temporary filename of the file in which the uploaded file was stored on the server. error: Error code. I.e.: UPLOAD_ERR_OK UPLOAD_ERR_INI_SIZE UPLOAD_ERR_FORM_SIZE UPLOAD_ERR_PARTIAL

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

UPLOAD_ERR_NO_FILE UPLOAD_ERR_NO_TMP_DIR UPLOAD_ERR_CANT_WRITE

5

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

$_FILES Usage Example Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP



6

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

Session introduction Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

• HTTP is designed as a stateless protocol. This is a problem for web application development. • A session is defined as the time the user is connected in a uninterrupted way. • Modern server-side script languages (such as PHP) have a complete management of the session, consisting of: – Detecting whether two requests are part of the same session (i.e. they correspond to the same user).

– Storing information associated to session.

• In PHP session is managed by using $_SESSION variable Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

7

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

Session in PHP Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP 1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

• PHP uses cookies (little information containers stored in user`s browser) to store the session. This is a common functional problem because sometimes cookies are disable in browser (for security reasons)

• When cookies are disabled, PHP use hidden variables. • Session management function hide this differences when programming in PHP. • The information to maintain the session is the sessionID (PHPSESSID); e.g.: PHPSESSID=a01vjqgvo3re5kiog962ikmbe7 • By default, PHP stores the session data in a temporary file with the PHPSESSID name; e.g.: “/tmp/php_a01vjqgvo3re5kiog962ikmbe7”

8

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

Session in PHP (II) Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP

• In order to read and store session data we have the $_SESSION variable.

• Usage Example:

1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos



login.php

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

main.php 9

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

Session management functions Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP

– session_start: Initialize session data. After its call we can use $_SESSION variable.

1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control 6. Clases y objetos 7. Clases predefinidas 3. Estilos de programación PHP

– session_destroy: Destroys all data registered to a session. – session_encode: Encodes the current session data as a string.

4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

– session_decode: Decodes session data from a string. – session_id: Get and/or set the current session id. 10

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP

• Form processing flow Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

1. Introducción 2. El lenguaje PHP

$_SESSION data

1. Comentarios 2. Tipos 3. Variables 4. Funciones

5. Estructuras de Control

FormMng.php

Form.php

6. Clases y objetos 7. Clases predefinidas



3. Estilos de programación PHP 4. Variables Globales 4.1. La variable $GLOBALS 4.2. La variable $_SERVER 4.3. La variable $_REQUEST 4.4. La variable $_SESSION

Sevilla, noviembre de 2006 Grupo de Ingeniería del Software

Sucess.php

yes

no ¿errors?

11

[Ángel US V7] Diseño: Amador Durán Toro (2003-2006)

Introducción a PHP Form.php

Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos

Get in touch

Social

© Copyright 2013 - 2024 MYDOKUMENT.COM - All rights reserved.