SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

PHP file Include Once script and example

If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once().  This will prevent problems with function redefinitions, variable value reassignments, etc.  Here is one example to explain this.  Before that please read the php include function to know the php include command.

Let us create one PHP file and name it as data.php . Here is the content of this file

<?
echo "Hello <br>";   // this will print Hello with one line break
?>

Now let us create one more file and from that we will be including the above data.php file . The name of the file will be inc.php and the code is given below.

<?
include "data.php";        // this will display Hello once
include "data.php";        // this will display Hello once
include "data.php";        // this will display Hello once
 
include_once "data.php"; // this will not display as the file is already included.
include_once "data.php";  // this will also not display as the file is already included.
?>

So here in the above code the echo command displaying Hello will be displayed three times and not five times.  The include_once() command will not include the data.php file again.


Discuss this tutorial at forum


PHP Redirect
Header Redirect & warning messages in PHP
Conditional Redirection
Include or calling files inside PHP pages
Include Once a file
PHP IP

 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.