Índice de contenidos
Instalación en Windows
Instalación en Ubuntu
Servidores seguros
Páginas dinámicas
Sintaxis básica
Operaciones
Arrays
Formatos de presentación
Operadores
Bucles
Extraer y ord. información
Funciones
Ficheros externos
Imágenes dinámicas
Gestión de directorios
Cookies y sesiones
Clases y objetos
Ficheros en formato PDF
Bases de datos MySQL
PHP y XML
PDO - Bases SQLite / MySQL
MySQL a traves de misqli
Algo de JavaScript y AJAXLas tablas de valores
En las tablas que hay al final de esta página podrás ver los valores actuales –clasificados por tipos– de algunas de las variables predefinidas de PHP. Esta información (variables y valores) está siendo extraida de la configuración de tu servidor y de este documento y se trata de variables de tipo superglobal tal como lo definíamos en esta página.
Probablemente te extrañará –justificadamente– la longitud y la estructura un tanto rara de estos nombres de variables. Cuando tratemos el tema de los arrays asociativos veremos que esa es la sintaxis habitual de ese tipo de variables.
Las nombres de las variables de cada uno de los tipos, sólo se diferencian en lo contenido entre los corchetes porque se trata de distintos elementos del mismo array asociativo y –tal como veremos– esa es la sintaxis típica de los array.
No vamos a agobiarte con una enumeración de variables y contenidos, pero a poco que observes las tablas de valores te darás cuenta de que es muy abundante y muy importante la información que recogen. Si analizas las variables de servidor te darás cuenta de que aparece un montón de información relativa a su configuración: nombre, rutas, nombres de páginas, IP del servidor, etcétera. Con los demás tipos ocurre algo similar.
Los distintos tipos
Veamos los diferentes tipos de variables predefinidas que existen en PHP. Por ahora, no te preocupes demasiado sobre la forma de utilizarlas. Las incluimos aquí como una simple enumeración y con una breve descripción de su utilidad. En temas posteriores haremos referencia a ellas. Por el momento nos bastará con conocer su existencia.
Estamos viendo los valores de las variables de de entorno (ENV) y las de servidor (SERVER), pero, además de ellas, existen algunas otras cuyos nombres y utilidades vamos a comentarte.
Variables de sesión
Las identificaremos por el nombre $_SESSION.
Este tipo de variables las utilizaremos cuando hagamos mención al uso de sesiones. La utilización de sesiones –ya abundaremos en ello– es una forma de recoger, de forma temporal en un documento del mismo carácter, información específica generada a través de los accesos de cada uno de los usuarios. Por ejemplo, cuando accedes a una cuenta de correo web y escribes tu clave y contraseña se crea un documento temporal en el servidor de correo con un número único y exclusivo para ese acceso –identificador de sesión– que te permite acceder a diferentes apartados sin necesidad de que reescribas, en cada una de las páginas, esos mismos valores.
Habrás comprobado también, más de una vez, su carácter efímero cuando al actualizar una página te ha aparecido ese mensaje típico que dice la sesion ha caducado.
Variables de los métodos GET y POST
Las identificaremos por los nombres $_GET y $_POST
Este tipo de variables –que utilizaremos con frecuencia– recogen la información que se envía desde el cliente para ser utilizada por el servidor. Recuerda el carácter dinámico de PHP y que ese dinamismo (interacción cliente – servidor) requiere que el servidor guarde y/o interprete los datos remitidos por el cliente. La existencia de los dos tipos se justifica porque también existen dos tipos de métodos (maneras) de enviar datos desde el cliente hasta el servidor. Cuando el método de envío es el llamado GET los datos se recogen en variables de este tipo, y, por el contrario, si ese método envío fuera POST se recogerían en aquellas.
Variables de transferencia de ficheros
Las identificaremos por el nombre $_FILES. Cuando se trata de la transferencia de un fichero desde el cliente hasta el servidor –«subir un fichero»– es necesario utilizar un procedimiento de envío distinto de los comentados en el párrafo anterior. Será en este caso cuando se utilicen variables de este tipo.
El tipo GLOBALS
A diferencia de las anteriores, las variables de este tipo, $GLOBALS,utilizan una sintaxis algo distinta ya no llevan el guión bajo detrás de $. Su finalidad es recoger en una tabla los nombres de todas la variables establecidas como globales –en cada momento– así como sus valores. Si observas la tabla que tienes al final de esta página quizá te sorprenda leer nombre o página. ¿De donde han salido esos valores?. Bueno... en esta página utilizamos scripts PHP y esos son los nombres de unas variables que hemos incluido en ellos.
Conocida la existencia de los diferentes tipos de variables predefinidas y vista esta tabla –a modo de ejemplo de su utilidad– no será preciso que profundicemos más en el asunto. Lo trataremos en el momento en el que tengamos que hacer uso de cada una de ellas.
Variables de servidor
| $_SERVER['UNIQUE_ID'] |
| n3AiXUg0jIEAAC2oAXgAAAAN |
| $_SERVER['HTTP_X_CC_ID'] |
| ccc04-02 |
| $_SERVER['HTTP_HOST'] |
| www.rinconastur.net |
| $_SERVER['HTTP_USER_AGENT'] |
| CCBot/1.0 (+http://www.commoncrawl.org/bot.html) |
| $_SERVER['HTTP_ACCEPT'] |
| text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q= 0.8,image/png,*/*;q=0.5 |
| $_SERVER['HTTP_ACCEPT_LANGUAGE'] |
| en-us,en;q=0.5 |
| $_SERVER['HTTP_ACCEPT_ENCODING'] |
| gzip |
| $_SERVER['HTTP_ACCEPT_CHARSET'] |
| ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| $_SERVER['HTTP_CONNECTION'] |
| close |
| $_SERVER['HTTP_CACHE_CONTROL'] |
| no-cache |
| $_SERVER['HTTP_PRAGMA'] |
| no-cache |
| $_SERVER['PATH'] |
| /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
| $_SERVER['SERVER_SIGNATURE'] |
| $_SERVER['SERVER_SOFTWARE'] |
| Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel 5 mod_bwlimited/1.4 PHP/5.2.11 |
| $_SERVER['SERVER_NAME'] |
| www.rinconastur.net |
| $_SERVER['SERVER_ADDR'] |
| 72.52.140.129 |
| $_SERVER['SERVER_PORT'] |
| 80 |
| $_SERVER['REMOTE_ADDR'] |
| 38.107.179.240 |
| $_SERVER['DOCUMENT_ROOT'] |
| /home/rinconas/public_html |
| $_SERVER['SERVER_ADMIN'] |
| webmaster@rinconastur.net |
| $_SERVER['SCRIPT_FILENAME'] |
| /home/rinconas/public_html/php/php30.php |
| $_SERVER['REMOTE_PORT'] |
| 59459 |
| $_SERVER['GATEWAY_INTERFACE'] |
| CGI/1.1 |
| $_SERVER['SERVER_PROTOCOL'] |
| HTTP/1.1 |
| $_SERVER['REQUEST_METHOD'] |
| GET |
| $_SERVER['QUERY_STRING'] |
| $_SERVER['REQUEST_URI'] |
| /php/php30.php |
| $_SERVER['SCRIPT_NAME'] |
| /php/php30.php |
| $_SERVER['PHP_SELF'] |
| /php/php30.php |
| $_SERVER['REQUEST_TIME'] |
| 1329973657 |
| $_SERVER['argv'] |
| $_SERVER['argc'] |
Variables GLOBALES
| $GLOBALS['GLOBALS']['GLOBALS'] |
| Array |
| $GLOBALS['GLOBALS']['_ENV'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_ENV_VARS'] |
| Array |
| $GLOBALS['GLOBALS']['_POST'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_POST_VARS'] |
| Array |
| $GLOBALS['GLOBALS']['_GET'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_GET_VARS'] |
| Array |
| $GLOBALS['GLOBALS']['_COOKIE'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_COOKIE_VARS'] |
| Array |
| $GLOBALS['GLOBALS']['_SERVER'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_SERVER_VARS'] |
| Array |
| $GLOBALS['GLOBALS']['_FILES'] |
| Array |
| $GLOBALS['GLOBALS']['HTTP_POST_FILES'] |
| Array |
| $GLOBALS['GLOBALS']['_REQUEST'] |
| Array |
| $GLOBALS['GLOBALS']['xyz_DOCUMENT_ROOT'] |
| C:/ServidoresLocales/Apache/htdocs |
| $GLOBALS['GLOBALS']['mi_xyz'] |
| $GLOBALS['GLOBALS']['xyz_SERVER_ROOT'] |
| C:/ServidoresLocales/Apache/ |
| $GLOBALS['GLOBALS']['xyz_INSTALL'] |
| C:/ServidoresLocales/ |
| $GLOBALS['GLOBALS']['xyz_DIR_INSTALL'] |
| ServidoresLocales |
| $GLOBALS['GLOBALS']['ver'] |
| ver.php?URL= |
| $GLOBALS['GLOBALS']['ver_extension'] |
| .php |
| $GLOBALS['GLOBALS']['extension'] |
| .php |
| $GLOBALS['GLOBALS']['prefijo'] |
| $GLOBALS['GLOBALS']['incluye'] |
| general.inc.php |
| $GLOBALS['GLOBALS']['prefx'] |
| $GLOBALS['GLOBALS']['prefx1'] |
| $GLOBALS['GLOBALS']['prefx0'] |
| $GLOBALS['GLOBALS']['opcion'] |
| I |
| $GLOBALS['GLOBALS']['anterior'] |
| php29.php |
| $GLOBALS['GLOBALS']['siguiente'] |
| php31.php |
| $GLOBALS['GLOBALS']['clave'] |
| Array |
| $GLOBALS['GLOBALS']['nombre'] |
| argc |
| $GLOBALS['GLOBALS']['nombre1'] |
| GLOBALS |
| $GLOBALS['GLOBALS']['valor'] |
| GLOBALS |
| $GLOBALS['GLOBALS']['nombre2'] |
| valor |
| $GLOBALS['_ENV']['TERM'] |
| vt100 |
| $GLOBALS['_ENV']['SSH_CLIENT'] |
| 80.35.161.51 54593 22 |
| $GLOBALS['_ENV']['CPANEL_IS_CRON'] |
| 0 |
| $GLOBALS['_ENV']['LD_LIBRARY_PATH'] |
| /usr/local/apache/lib: |
| $GLOBALS['_ENV']['PATH'] |
| /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
| $GLOBALS['_ENV']['PWD'] |
| /usr/local/cpanel/whostmgr/docroot |
| $GLOBALS['_ENV']['SHLVL'] |
| 1 |
| $GLOBALS['_ENV']['RESTARTSRV'] |
| 1 |
| $GLOBALS['_ENV']['_'] |
| /usr/local/apache/bin/httpd |
| $GLOBALS['HTTP_ENV_VARS']['TERM'] |
| vt100 |
| $GLOBALS['HTTP_ENV_VARS']['SSH_CLIENT'] |
| 80.35.161.51 54593 22 |
| $GLOBALS['HTTP_ENV_VARS']['CPANEL_IS_CRON'] |
| 0 |
| $GLOBALS['HTTP_ENV_VARS']['LD_LIBRARY_PATH'] |
| /usr/local/apache/lib: |
| $GLOBALS['HTTP_ENV_VARS']['PATH'] |
| /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
| $GLOBALS['HTTP_ENV_VARS']['PWD'] |
| /usr/local/cpanel/whostmgr/docroot |
| $GLOBALS['HTTP_ENV_VARS']['SHLVL'] |
| 1 |
| $GLOBALS['HTTP_ENV_VARS']['RESTARTSRV'] |
| 1 |
| $GLOBALS['HTTP_ENV_VARS']['_'] |
| /usr/local/apache/bin/httpd |
| $GLOBALS['_SERVER']['UNIQUE_ID'] |
| n3AiXUg0jIEAAC2oAXgAAAAN |
| $GLOBALS['_SERVER']['HTTP_X_CC_ID'] |
| ccc04-02 |
| $GLOBALS['_SERVER']['HTTP_HOST'] |
| www.rinconastur.net |
| $GLOBALS['_SERVER']['HTTP_USER_AGENT'] |
| CCBot/1.0 (+http://www.commoncrawl.org/bot.html) |
| $GLOBALS['_SERVER']['HTTP_ACCEPT'] |
| text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 |
| $GLOBALS['_SERVER']['HTTP_ACCEPT_LANGUAGE'] |
| en-us,en;q=0.5 |
| $GLOBALS['_SERVER']['HTTP_ACCEPT_ENCODING'] |
| gzip |
| $GLOBALS['_SERVER']['HTTP_ACCEPT_CHARSET'] |
| ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| $GLOBALS['_SERVER']['HTTP_CONNECTION'] |
| close |
| $GLOBALS['_SERVER']['HTTP_CACHE_CONTROL'] |
| no-cache |
| $GLOBALS['_SERVER']['HTTP_PRAGMA'] |
| no-cache |
| $GLOBALS['_SERVER']['PATH'] |
| /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
| $GLOBALS['_SERVER']['SERVER_SIGNATURE'] |
| $GLOBALS['_SERVER']['SERVER_SOFTWARE'] |
| Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.2.11 |
| $GLOBALS['_SERVER']['SERVER_NAME'] |
| www.rinconastur.net |
| $GLOBALS['_SERVER']['SERVER_ADDR'] |
| 72.52.140.129 |
| $GLOBALS['_SERVER']['SERVER_PORT'] |
| 80 |
| $GLOBALS['_SERVER']['REMOTE_ADDR'] |
| 38.107.179.240 |
| $GLOBALS['_SERVER']['DOCUMENT_ROOT'] |
| /home/rinconas/public_html |
| $GLOBALS['_SERVER']['SERVER_ADMIN'] |
| webmaster@rinconastur.net |
| $GLOBALS['_SERVER']['SCRIPT_FILENAME'] |
| /home/rinconas/public_html/php/php30.php |
| $GLOBALS['_SERVER']['REMOTE_PORT'] |
| 59459 |
| $GLOBALS['_SERVER']['GATEWAY_INTERFACE'] |
| CGI/1.1 |
| $GLOBALS['_SERVER']['SERVER_PROTOCOL'] |
| HTTP/1.1 |
| $GLOBALS['_SERVER']['REQUEST_METHOD'] |
| GET |
| $GLOBALS['_SERVER']['QUERY_STRING'] |
| $GLOBALS['_SERVER']['REQUEST_URI'] |
| /php/php30.php |
| $GLOBALS['_SERVER']['SCRIPT_NAME'] |
| /php/php30.php |
| $GLOBALS['_SERVER']['PHP_SELF'] |
| /php/php30.php |
| $GLOBALS['_SERVER']['REQUEST_TIME'] |
| 1329973657 |
| $GLOBALS['_SERVER']['argv'] |
| Array |
| $GLOBALS['_SERVER']['argc'] |
| 0 |
| $GLOBALS['HTTP_SERVER_VARS']['UNIQUE_ID'] |
| n3AiXUg0jIEAAC2oAXgAAAAN |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_X_CC_ID'] |
| ccc04-02 |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'] |
| www.rinconastur.net |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'] |
| CCBot/1.0 (+http://www.commoncrawl.org/bot.html) |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_ACCEPT'] |
| text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_ACCEPT_LANGUAGE'] |
| en-us,en;q=0.5 |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_ACCEPT_ENCODING'] |
| gzip |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_ACCEPT_CHARSET'] |
| ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_CONNECTION'] |
| close |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_CACHE_CONTROL'] |
| no-cache |
| $GLOBALS['HTTP_SERVER_VARS']['HTTP_PRAGMA'] |
| no-cache |
| $GLOBALS['HTTP_SERVER_VARS']['PATH'] |
| /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_SIGNATURE'] |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_SOFTWARE'] |
| Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.2.11 |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_NAME'] |
| www.rinconastur.net |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_ADDR'] |
| 72.52.140.129 |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_PORT'] |
| 80 |
| $GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR'] |
| 38.107.179.240 |
| $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] |
| /home/rinconas/public_html |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_ADMIN'] |
| webmaster@rinconastur.net |
| $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_FILENAME'] |
| /home/rinconas/public_html/php/php30.php |
| $GLOBALS['HTTP_SERVER_VARS']['REMOTE_PORT'] |
| 59459 |
| $GLOBALS['HTTP_SERVER_VARS']['GATEWAY_INTERFACE'] |
| CGI/1.1 |
| $GLOBALS['HTTP_SERVER_VARS']['SERVER_PROTOCOL'] |
| HTTP/1.1 |
| $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] |
| GET |
| $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'] |
| $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] |
| /php/php30.php |
| $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME'] |
| /php/php30.php |
| $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] |
| /php/php30.php |
| $GLOBALS['HTTP_SERVER_VARS']['REQUEST_TIME'] |
| 1329973657 |
| $GLOBALS['HTTP_SERVER_VARS']['argv'] |
| Array |
| $GLOBALS['HTTP_SERVER_VARS']['argc'] |
| 0 |
| $GLOBALS['xyz_DOCUMENT_ROOT'] |
| C:/ServidoresLocales/Apache/htdocs |
| $GLOBALS['mi_xyz'] |
| $GLOBALS['xyz_SERVER_ROOT'] |
| C:/ServidoresLocales/Apache/ |
| $GLOBALS['xyz_INSTALL'] |
| C:/ServidoresLocales/ |
| $GLOBALS['xyz_DIR_INSTALL'] |
| ServidoresLocales |
| $GLOBALS['ver'] |
| ver.php?URL= |
| $GLOBALS['ver_extension'] |
| .php |
| $GLOBALS['extension'] |
| .php |
| $GLOBALS['prefijo'] |
| $GLOBALS['incluye'] |
| general.inc.php |
| $GLOBALS['prefx'] |
| $GLOBALS['prefx1'] |
| $GLOBALS['prefx0'] |
| $GLOBALS['opcion'] |
| I |
| $GLOBALS['anterior'] |
| php29.php |
| $GLOBALS['siguiente'] |
| php31.php |
| $GLOBALS['clave'] |
| php31.php |
| $GLOBALS['nombre'] |
| argc |
| $GLOBALS['nombre1'] |
| nombre |
| $GLOBALS['valor'] |
| 0 |
| $GLOBALS['nombre2'] |
| argc |