SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 
 

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.



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


Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.