Php, manual completo

910 views
839 views

Published on

Manual php completo

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
910
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
41
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Php, manual completo

  1. 1. Manual de PHP Stig Sæther Bakken Alexander Aulbach Egon Schmid Jim Winstead Lars Torben Wilson Rasmus Lerdorf Andrei Zmievski Jouni Ahto
  2. 2. Editado por Rafael Martínez 24-03-2002 Copyright © 1997, 1998, 1999, 2000, 2001, 2002 por por el Grupo de documentación de PHP Copyright Este manual es © Copyright 1997, 1998, 1999, 2000, 2001, 2002 del Grupo de documentación de PHP. Los miembros de este grupo se encuentran listados en la primera página de este manual. Este manual puede ser redistribuido bajo los términos de la "GNU General Public License" publicada por la "Free Software Foundation"; tanto bajo la versión 2 de esta licencia o bajo versiones posteriores.
  3. 3. Manual de PHP por Stig Sæther Bakken, Alexander Aulbach, Egon Schmid, Jim Winstead, Lars Torben Wilson, Rasmus Lerdorf, Andrei Zmievski, y Jouni Ahto Editado por Rafael Martínez Publicado 24-03-2002 Copyright © 1997, 1998, 1999, 2000, 2001, 2002 por por el Grupo de documentación de PHP Copyright Este manual es © Copyright 1997, 1998, 1999, 2000, 2001, 2002 del Grupo de documentación de PHP. Los miembros de este grupo se encuentran listados en la primera página de este manual. Este manual puede ser redistribuido bajo los términos de la "GNU General Public License" publicada por la "Free Software Foundation"; tanto bajo la versión 2 de esta licencia o bajo versiones posteriores.
  4. 4. Tabla de contenidos Prefacio ........................................................................................................................................................i Sobre este Manual...............................................................................................................................i Sobre la traducción..............................................................................................................................i I. Conceptos Básicos ..................................................................................................................................1 1. Introducción ...................................................................................................................................1 Qué es PHP?.............................................................................................................................2 Qué se puede hacer con PHP?..................................................................................................2 Corta historia de PHP ...............................................................................................................3 2. Instalación ......................................................................................................................................4 Bajándose la última versión......................................................................................................5 Instalación en sistemas UNIX ..................................................................................................5 Instrucciones Rápidas de Instalación (Versión Módulo de Apache) ..............................5 Configuración..................................................................................................................6 Módulo del Apache.........................................................................................................6 Módulo fhttpd .................................................................................................................6 CGI version.....................................................................................................................6 Opciones de soporte para Base de Datos........................................................................7 Adabas D...............................................................................................................7 dBase .....................................................................................................................7 filePro ....................................................................................................................7 mSQL ....................................................................................................................7 MySQL..................................................................................................................8 iODBC...................................................................................................................8 OpenLink ODBC...................................................................................................8 Oracle ....................................................................................................................8 PostgreSQL ...........................................................................................................8 Solid ......................................................................................................................9 Sybase....................................................................................................................9 Sybase-CT .............................................................................................................9 Velocis ...................................................................................................................9 Una librería a medida de ODBC .........................................................................10 ODBC Unificado.................................................................................................10 LDAP...................................................................................................................10 Otras opciones de configuración...................................................................................10 --with-mcrypt=DIR.............................................................................................11 --enable-sysvsem.................................................................................................11 --enable-sysvshm.................................................................................................11 --with-xml............................................................................................................11 --enable-maintainer-mode ...................................................................................11 --with-system-regex.............................................................................................11 --with-config-file-path .........................................................................................12 --with-exec-dir.....................................................................................................12 --enable-debug.....................................................................................................12 --enable-safe-mode..............................................................................................12 --enable-track-vars...............................................................................................12 iv
  5. 5. --enable-magic-quotes.........................................................................................13 --enable-debugger................................................................................................13 --enable-discard-path...........................................................................................13 --enable-bcmath...................................................................................................13 --enable-force-cgi-redirect ..................................................................................13 --disable-short-tags..............................................................................................14 --enable-url-includes ...........................................................................................14 --disable-syntax-hl...............................................................................................14 CPPFLAGS y LDFLAGS ...................................................................................14 Construyendo................................................................................................................15 Probando .......................................................................................................................15 Comprobando la velocidad ...........................................................................................15 Instalación en sistemas Windows 95/98/NT...........................................................................15 Pasos Generales de Instalación .....................................................................................15 Windows 95/98/NT y PWS/IIS 3..................................................................................16 Windows NT e IIS 4 .....................................................................................................17 Windows 9x/NT y Apache 1.3.x...................................................................................18 Omni HTTPd 2.0b1 para Windows ..............................................................................18 Módulos del PHP..........................................................................................................18 ¿Problemas?............................................................................................................................19 Lea las PMF (FAQ).......................................................................................................19 Informes de error...........................................................................................................19 Otros problemas............................................................................................................19 3. Configuración...............................................................................................................................21 El archivo de configuración....................................................................................................22 Directivas Generales de Configuración.........................................................................22 Directivas de Configuración de Correo.........................................................................26 Directivas de Configuración de Modo Seguro..............................................................27 Directivas de Configuración del Debugger...................................................................27 Directivas de Carga de Extensiones..............................................................................27 Directivas de Configuración de MySQL.......................................................................28 Directivas de Configuración de mSQL .........................................................................28 Directivas de Configuración de Postgres ......................................................................28 SESAM Configuration Directives.................................................................................29 Directivas de Configuración de Sybase ........................................................................29 Directivas de Configuración de Sybase-CT..................................................................30 Directivas de Configuración de Informix......................................................................31 Directivas de Configuración de Matemática BC...........................................................32 Directivas de Configuración de Capacidades de los Navegadores................................32 Directivas Unificadas de Configuración de ODBC.......................................................32 4. Seguridad......................................................................................................................................34 Binarios CGI...........................................................................................................................35 Posibles ataques ............................................................................................................35 Caso 1: solamente se sirven ficheros publicos..............................................................36 Caso 2: usando --enable-force-cgi-redirect...................................................................36 Caso 3: Usando doc_root or user_dir............................................................................36 Caso 4: Analizador PHP fuera del arbol web. ..............................................................37 Modulo Apache ......................................................................................................................37 v
  6. 6. II. Referencia del Lenguaje.....................................................................................................................39 5. Sintaxis básica..............................................................................................................................39 Saliendo de HTML.................................................................................................................40 Separación de instrucciones ...................................................................................................40 Comentarios............................................................................................................................40 6. Types ............................................................................................................................................42 Enteros....................................................................................................................................43 Números en punto flotante......................................................................................................43 Cadenas...................................................................................................................................43 Conversión de cadenas..................................................................................................45 Arrays .....................................................................................................................................46 Arrays unidimensionales...............................................................................................46 Arrays Multidimensionales...........................................................................................47 Objetos....................................................................................................................................48 Inicialización de Objetos...............................................................................................49 Type juggling..........................................................................................................................49 Forzado de tipos............................................................................................................50 7. Variables.......................................................................................................................................52 Conceptos Básicos..................................................................................................................53 Variables predefinidas.............................................................................................................54 Variables de Apache......................................................................................................54 Variables de entorno......................................................................................................56 Variables de PHP...........................................................................................................56 Ambito de las variables ..........................................................................................................57 Variables variables..................................................................................................................59 Variables externas a PHP........................................................................................................60 Formularios HTML (GET y POST) .............................................................................60 IMAGE SUBMIT variable names.......................................................................61 Cookies HTTP ..............................................................................................................61 Variables de entorno......................................................................................................62 Puntos en los nombres de variables de entrada.............................................................62 Determinando los tipos de variables.............................................................................63 8. Constantes ....................................................................................................................................64 9. Expresiones ..................................................................................................................................67 10. Operadores .................................................................................................................................71 Operadores Aritméticos..........................................................................................................72 Operadores de Asignación......................................................................................................72 Operadores Bit a bit................................................................................................................72 Operadores de Comparación ..................................................................................................73 Operador de ejecución............................................................................................................74 Operadores de Incremento/decremento..................................................................................74 Operadores Lógicos................................................................................................................75 Precedencia de Operadores.....................................................................................................75 Operadores de Cadenas ..........................................................................................................76 11. Estructuras de Control................................................................................................................78 if............................................................................................................................................79 else .......................................................................................................................................79 elseif ...................................................................................................................................80 vi
  7. 7. Sintaxis Alternativa de Estructuras de Control.......................................................................80 while .....................................................................................................................................81 do..while.............................................................................................................................82 for..........................................................................................................................................83 foreach.................................................................................................................................84 break .....................................................................................................................................86 continue...............................................................................................................................87 switch ...................................................................................................................................88 require() ..................................................................................................................................90 include()..................................................................................................................................91 require_once().........................................................................................................................94 include_once() ........................................................................................................................96 12. Funciones ...................................................................................................................................98 Funciones definidas por el usuario .........................................................................................99 Parámetros de las funciones ...................................................................................................99 Pasar parámetros por referencia....................................................................................99 Parámetros por defecto ...............................................................................................100 Lista de longitud variable de parámetros....................................................................101 Devolver valores...................................................................................................................101 old_function ....................................................................................................................102 Funciones variable................................................................................................................102 13. Clases y Objetos.......................................................................................................................104 class ...................................................................................................................................105 14. References Explained...............................................................................................................108 What are References.............................................................................................................109 What do References..............................................................................................................109 What aren’t References ........................................................................................................109 Returning References ...........................................................................................................110 Unsetting References............................................................................................................110 Spotting the Reference .........................................................................................................110 global References.....................................................................................................111 $this..........................................................................................................................111 III. Características.................................................................................................................................112 15. Manejando errores....................................................................................................................112 16. Creando imágenes GIF.............................................................................................................114 17. Autentificación HTTP con PHP...............................................................................................116 18. Cookies.....................................................................................................................................119 19. El envío de archivos .................................................................................................................121 Envío de archivos con el método POST ...............................................................................122 Errores comunes ...................................................................................................................122 Envío de más de un archivo..................................................................................................123 Soporte del método PUT ......................................................................................................123 20. Usando archivos remotos .........................................................................................................125 21. Manejando conexiones.............................................................................................................128 22. Conexiones persistentes a bases de datos.................................................................................130 23. Safe Mode ................................................................................................................................133 Functions restricted/disabled by safe mode..........................................................................135 vii
  8. 8. IV. Referencia de las Funciones ...........................................................................................................139 I. Funciones específicas de Apache................................................................................................139 apache_lookup_uri ...............................................................................................................140 apache_note ..........................................................................................................................140 getallheaders.........................................................................................................................140 virtual....................................................................................................................................141 II. Funciones de matrices ...............................................................................................................142 array......................................................................................................................................143 array_count_values...............................................................................................................143 array_flip...............................................................................................................................144 array_keys.............................................................................................................................144 array_merge..........................................................................................................................145 array_pad ..............................................................................................................................145 array_pop..............................................................................................................................146 array_push ............................................................................................................................146 array_reverse ........................................................................................................................147 array_shift.............................................................................................................................147 array_slice.............................................................................................................................148 array_splice...........................................................................................................................149 array_unshift.........................................................................................................................150 array_values..........................................................................................................................150 array_walk ............................................................................................................................151 arsort.....................................................................................................................................152 asort ......................................................................................................................................152 compact.................................................................................................................................153 count .....................................................................................................................................154 current...................................................................................................................................154 each.......................................................................................................................................155 end ........................................................................................................................................156 extract ...................................................................................................................................156 in_array.................................................................................................................................158 key ........................................................................................................................................158 krsort.....................................................................................................................................158 ksort......................................................................................................................................159 list .........................................................................................................................................159 next .......................................................................................................................................160 pos.........................................................................................................................................160 prev.......................................................................................................................................161 rango.....................................................................................................................................161 reset.......................................................................................................................................161 rsort.......................................................................................................................................162 shuffle ...................................................................................................................................162 sizeof.....................................................................................................................................163 sort........................................................................................................................................163 uasort ....................................................................................................................................163 uksort....................................................................................................................................163 usort......................................................................................................................................164 III. Funciones Ortográficas ............................................................................................................166 viii
  9. 9. aspell_new ............................................................................................................................167 aspell_check .........................................................................................................................167 aspell_check-raw ..................................................................................................................167 aspell_suggest.......................................................................................................................168 IV. Funciones matemáticas de precisión arbitraria........................................................................169 bcadd.....................................................................................................................................170 bccomp .................................................................................................................................170 bcdiv .....................................................................................................................................170 bcmod ...................................................................................................................................170 bcmul....................................................................................................................................170 bcpow....................................................................................................................................171 bcscale ..................................................................................................................................171 bcsqrt ....................................................................................................................................171 bcsub.....................................................................................................................................171 V. Bzip2 Compression Functions ..................................................................................................173 bzclose ..................................................................................................................................175 bzcompress ...........................................................................................................................175 bzdecompress .......................................................................................................................175 bzerrno..................................................................................................................................176 bzerror...................................................................................................................................176 bzerrstr..................................................................................................................................177 bzflush...................................................................................................................................177 bzopen...................................................................................................................................177 bzread ...................................................................................................................................178 bzwrite ..................................................................................................................................178 VI. Funciones de calendario...........................................................................................................180 JDToGregorian .....................................................................................................................181 GregorianToJD .....................................................................................................................181 JDToJulian............................................................................................................................181 JulianToJD............................................................................................................................181 JDToJewish...........................................................................................................................182 JewishToJD...........................................................................................................................182 JDToFrench ..........................................................................................................................182 FrenchToJD ..........................................................................................................................182 JDMonthName .....................................................................................................................183 JDDayOfWeek......................................................................................................................183 easter_date ............................................................................................................................184 easter_days ...........................................................................................................................184 VII. CCVS API Functions .............................................................................................................186 ccvs_init................................................................................................................................187 ccvs_done .............................................................................................................................187 ccvs_new ..............................................................................................................................187 ccvs_add ...............................................................................................................................187 ccvs_delete ...........................................................................................................................188 ccvs_auth ..............................................................................................................................188 ccvs_return ...........................................................................................................................188 ccvs_reverse..........................................................................................................................189 ccvs_sale...............................................................................................................................189 ix
  10. 10. ccvs_void..............................................................................................................................189 ccvs_status............................................................................................................................190 ccvs_count ............................................................................................................................190 ccvs_lookup..........................................................................................................................190 ccvs_report ...........................................................................................................................190 ccvs_command .....................................................................................................................191 ccvs_textvalue ......................................................................................................................191 VIII. soporte de las funciones COM para Windows ......................................................................192 com_load ..............................................................................................................................193 com_invoke...........................................................................................................................193 com_propget.........................................................................................................................193 com_get ................................................................................................................................193 com_propput.........................................................................................................................193 com_propset .........................................................................................................................193 com_set.................................................................................................................................194 IX. Funciones de Clases/Objectos .................................................................................................195 get_class_methods................................................................................................................196 get_class_vars.......................................................................................................................196 get_object_vars.....................................................................................................................196 method_exists.......................................................................................................................196 X. Funciones de ClibPDF ..............................................................................................................197 cpdf_global_set_document_limits........................................................................................200 cpdf_set_creator ...................................................................................................................200 cpdf_set_title ........................................................................................................................200 cpdf_set_subject ...................................................................................................................200 cpdf_set_keywords ...............................................................................................................200 cpdf_open .............................................................................................................................201 cpdf_close.............................................................................................................................201 cpdf_page_init ......................................................................................................................201 cpdf_finalize_page................................................................................................................202 cpdf_finalize .........................................................................................................................202 cpdf_output_buffer ...............................................................................................................202 cpdf_save_to_file..................................................................................................................203 cpdf_set_current_page..........................................................................................................203 cpdf_begin_text ....................................................................................................................203 cpdf_end_text .......................................................................................................................203 cpdf_show.............................................................................................................................204 cpdf_show_xy.......................................................................................................................204 cpdf_text...............................................................................................................................204 cpdf_set_font ........................................................................................................................205 cpdf_set_leading...................................................................................................................205 cpdf_set_text_rendering .......................................................................................................205 cpdf_set_horiz_scaling.......................................................