<HTML ><HEAD ><TITLE >require</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Control Structures" HREF="control-structures.html"><LINK REL="PREVIOUS" TITLE="return" HREF="function.return.html"><LINK REL="NEXT" TITLE="include" HREF="function.include.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.return.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 12. Control Structures</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.include.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="function.require" ></A ><A HREF="function.require.html" ><B CLASS="function" >require()</B ></A ></H1 ><P > The <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > statement includes and evaluates the specific file. </P ><P > <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A >. </P ><P > <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > and <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A > are identical in every way except how they handle failure. <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A > produces a <A HREF="phpdevel-errors.html#internal.e-warning" >Warning</A > while <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > results in a <A HREF="phpdevel-errors.html#internal.e-error" > Fatal Error</A >. In other words, don't hesitate to use <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > if you want a missing file to halt processing of the page. <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A > does not behave this way, the script will continue regardless. Be sure to have an appropriate <A HREF="configuration.directives.html#ini.include-path" >include_path</A > setting as well. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5135" ></A ><P ><B >Example 12-2. Basic <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php require 'prepend.php'; require $somefile; require ('somefile.txt'); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See the <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A > documentation for more examples. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Prior to PHP 4.0.2, the following applies: <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A >. However, if the line on which the <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A >. Although the code contained in the target file is still subject to the loop, the <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A > itself happens only once. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Windows versions of <TT CLASS="literal" >PHP</TT > prior to PHP 4.3 do not support accessing remote files via this function, even if <A HREF="ref.filesystem.html#ini.allow-url-fopen" >allow_url_fopen</A > is enabled. </P ></TD ></TR ></TABLE ></DIV ><P > See also <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A >, <A HREF="function.require-once.html" ><B CLASS="function" >require_once()</B ></A >, <A HREF="function.include-once.html" ><B CLASS="function" >include_once()</B ></A >, <A HREF="function.eval.html" ><B CLASS="function" >eval()</B ></A >, <A HREF="function.file.html" ><B CLASS="function" >file()</B ></A >, <A HREF="function.readfile.html" ><B CLASS="function" >readfile()</B ></A >, <A HREF="function.virtual.html" ><B CLASS="function" >virtual()</B ></A > and <A HREF="configuration.directives.html#ini.include-path" >include_path</A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.return.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.include.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >return</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="control-structures.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.include.html" ><B CLASS="function" >include()</B ></A ></TD ></TR ></TABLE ></DIV ></BODY ></HTML >