SQL PHP HTML ASP JavaScript articles and free scripts to download
 

PHP Include file script and example


By using PHP include() function and file can be used (included ) to any script or file. This is required where we have a common set of code to be used or any declarations or say the database connection is required for the script. All the files in the script can call the file storing database information by using include command and the set of code having all the information about database connection inside the included file gets attached to the main file.

It is important to note that when a file is included by using include functions then its is parsed as html mode unless the included file has php start and end tags inside it. Here is a simple example of PHP include.

include "include/config.php";


This will include the file name config.php of the include directory. Please note that here we have used relative path in respect to the script running. "include/config.php" is the file name config.php inside the directory name include.

If the file is one step above ( or towards root ) the present directory then we can call the file like this

include "../config.php";


If we are keeping any PHP code inside the config.php file then we must use PHP start and end tags in those area (<? And ?> ). Without this all are taken as html code only.

If we are including the file and if there is a chance that we may declare some functions or variables again then we can use the function include_once() which will take care of this.

PHP function include() can work for internal files only. This way we can't include external files( say in another server ) to our script.
To read an external URL it is better to use fopen() .


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.