Include in PHP

Advertisements

File Download in PHP Display Date and Time in PHP

Require in PHP

The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.

Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

Syntax

include 'filename';

or

require 'filename';

footer.php

<?php

echo "<p>Copyright © 1999-" . date("Y") . " Sitesbay.com</p>";

?>

home-page.php

<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>

</body>
</html>

home-page.php

<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php require 'footer.php';?>

</body>
</html>

Difference between Include and Require

require will produce a fatal error (E_COMPILE_ERROR) and stop the script. Include will only produce a warning (E_WARNING) and the script will continue.

Use include if you don't mind your script continuing without loading the file (in case it doesn't exist etc) and you can (although you shouldn't) live with a Warning error message being displayed. Using require means your script will halt if it can't load the specified file, and throw a Fatal error.

when a file is included with the include statement and PHP cannot find it, the script will continue to execute. In case of required file can't be execute.


File Download in PHP Display Date and Time in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements