MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

PHP 7 Intermediate Essential Guide- PHP include_once & require_once

In this blog, I am going to Explain How to include_once & require_once in PHP. So within PHP, It’s actually possible to include PHP people files within other PHP files. It means when you use include_once & require_once more than one in any PHP file and you calling script it will be shown or print only one time if found more than once then it will be ignored.

So I’ve created a few other PHP files. And typically we’re going to use this for header footer and different files. So as you can see here within the header I’ve got what’s called page header and I’ve actually included some code in here as well.

And the same thing for the footer so got the page footer so let’s just writing that code into “footer.php“. And I’m also including some I should call the void then. And setting a variable called footer with this is the footer.

So now I can go over to my main index page and if I had an “header.php” set up so I’ve got my header here and title and then I’ve got my body. And in this body, I always wanted to have a header. And I want to have a footer so these are just going to be content headers and footers. Normally I know what you’re probably thinking well why wouldn’t I put this into the header and this in the footer so he can do that as well.

First and then I’m also going to call out that variable that’s being set up within PHP. So we’ll just see what our output is and we can see that we get that initial content and then we get the value of head.
There are also some additional ones where you could include it once. So if we had something like require or include and again to work almost identically.

So that’s the difference between required once and require. And the same thing for include and include once. So they’re going to work relatively the same way. Including the requires.

File explorer showing a header-footer folder and index.php file

Output-

Browser output of require-once index.php showing header, body and footer sections

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Encryption using RSA public and Private Key using PHP

PHP's OpenSSL extension can create an RSA key pair, encrypt data with the public key and decrypt it with the private key. This page explains the gist…

Read More

Encryption using Public key and Private key in PHP using mySql database

This tutorial shows how to generate an RSA key pair with PHP's OpenSSL extension, encrypt form input with the public key, store the ciphertext in MySQL, and…

Read More

How to see number of emails sent using smtp in laravel

Laravel does not count or log SMTP emails by default, so a grep will only return a real number once your application writes one log line for…

Read More

What are the Authentication type in phpmyadmin which for config.inc.php

phpMyAdmin supports four authentication types, set per server with $cfg['Servers'][$i]['auth_type'] in config.inc.php: cookie (the default), config, http and signon. This page explains how each one works and…

Read More

What is opcache and Install / Configure in Linux

OPcache is PHP's built-in bytecode cache. It keeps compiled scripts in shared memory so PHP doesn't have to parse and compile the same files on every request….

Read More

PHP Code for Godaddy VPS Server SMTP Email Relay

This page shows how to send email from a GoDaddy VPS through GoDaddy's SMTP relay on port 25 with plain PHP sockets and no extra libraries. Below…

Read More