How to include other PHP file in your current file
You can use the content from one PHP file to another.
Include("filename.php");
Here filename.php is present on the same path as the file in which you are currently working.
You can also use require in lieu of include. Eg.
Require("filename.php");
These two functions are very vital because their usage is lot in the websites.
Suppose you create a website, it has more than 20 pages but this website has same header and footer. So we will create separate files of header and footer say "header.php" and "footer.php"
Eg. Lets we create a file index.php and include two files in it.
include("header.php");
echo "This is a nice example";
include("footer.php");
?>
Difference between include and require?
If you are using require("filename.php") and "filename.php" file is not present on this path, then it will display a fatal error.
If you are using include("filename.php") and "filename.php" file is not present on this path, then it will display warning message only.
Leave a comment