PHP Include and Require function .

Published: 24 February 2017
on channel: Student Projects Live
162
0

Welcome to PHP programming,

We can insert a contents of a file into a PHP file before the server executes it, with the
include() or require() function.

The two functions are identical in every way, except how they handle errors.

The include() function generates a warning but the script will continue execution.

The require() function generates a fatal error and the script execution will stop after the error.

These functions are used to create elements that can be reused on multiple pages.

This can save the developer a considerable amount of time.

The include() function

This function takes all the text in a specified file and copies it into the file that uses the
include function.

Let us write a PHP code

Save it in our server i.e., xampp/htdocs

To include header file in a page, use the include() function

Save this in our server i.e., xampp/htdocs

Run the code using the url http://localhost/phphome.php

This is how include() function works.

Let us see how include() function gives error messages if the wrong.php file doesnot exist

save this code in our server i.e, xampp/htdocs

Run this code using the url http://localhost/phpinclude.php

In This after the error is encountered further execution takes place.

The require() function

The require() function is identical to include(), except that it handles errors differently.

Let us write a PHP code

Save it in our server i.e, xampp/htdocs

Let us include the above code in the page

Save it in our server i.e., xampp/htdocs

Run the code using the url http://localhost/phphome1.php

This is how require() function works.

Let us see how require() function gives error messages if the wrong.php file doesnot exist

save the code in our server i.e., xampp/htdocs

run the code using the url http://localhost/phprequire.php

In this after the error is encountered further execution doesnot takes place.

Thank You.

Created by Krithika

For source code kindly refer www.studentprojects.live

Do you have Any queries? Contact us in Whatsapp :- +91-9972853368

#studentprojects #phpcode


On this page of the site you can watch the video online PHP Include and Require function . with a duration of hours minute second in good quality, which was uploaded by the user Student Projects Live 24 February 2017, share the link with friends and acquaintances, this video has already been watched 162 times on youtube and it was liked by 0 viewers. Enjoy your viewing!