The include() statement includes and evaluates the specified file.

The documentation below also applies to require().

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include() will finally check in the calling script’s own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.

If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.

For more information on how PHP handles including files and the include path, see the documentation for include_path.

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

Example #1 Basic include() example

vars.php
<?php

$color = 'green';
$fruit = 'apple';

?>

test.php
<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A green apple

?>

If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function. An exception to this rule are magic constants which are evaluated by the parser before the include occurs.

Example #2 Including within functions

<?php

function foo()
{
global $color;

include 'vars.php';

echo "A $color $fruit";
}

/* vars.php is in the scope of foo() so *
* $fruit is NOT available outside of this *
* scope. $color is because we declared it *
* as global. */

foo(); // A green apple
echo "A $color $fruit"; // A green

?>

When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.

If “URL fopen wrappers” are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper – see Supported Protocols and Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file’s variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Eduardo Saverin,Co-fundador de Facebook renunció a la ciudadanía estadounidense Eduardo Saverin, co- fundador de Facebook que se hizo mundialmente conocido después de la película de la red social, renunció a su ciudadanía estadoun...
Browser Support , herramienta para verificar el CSS en todos los navegadores Browser Support es un sencillo motor de búsqueda que nos permite averiguar que propiedades CSS son soportados por los principales navegadores. Su m...
Guia CSS,Las propiedades CSS, I Parte Conceptos básicos Agrupación La Agrupacion permite al autor asignar una declaracion a múltiples elementos (selectores).H1, H2, H3, H5 ...
Firefox 5 versión candidata Como parte del nuevo ciclo de actualizaciones del navegador de la Fundación Mozilla, el canal beta acaba de lanzar Firefox 5 Release Candidate. Ent...
generar ingresos con Google Adsense Desde que fue lanzado en 2003, el programa de Google adsense ha revolucionado la publicidad en Internet, traduciendo las visitas de personas a sitios ...
Estudio Revela que los países que usan mas las Redes Sociales son Indonesia, Argentina y Rusia Un estudio realizado por la consultora Ipsos/Reuters muestra que a pesar de que el mail sigue siendo el rey de las comunicaciones en el mundo de inter...
En España el 76% de las empresas prohiben entrar a redes sociales a sus empleados La penetración de las redes sociales en la sociedad española es innegable, con usuarios accediendo a ellas de forma diaria. Eso sí, el acceso no se ha...
Que es el Link building Linkbuilding o construcción de enlaces, es una de las estrategias del SEO que consiste en conseguir que otras páginas web enlacen a la página que inte...
Nuevo Google Analytics y otras mejoras Google ha lanzado una interesante mejora en su servicio Analytics con la que obtener nuevos informes con datos en tiempo real acerca de cómo se compor...
Facebook,casi en los 700 millones de usuarios Facebook podría llegar a los 700 millones de usuarios antes de lo esperado. Las previsiones del gigante de Internet liderado por Mark Zuckerberg estim...