Home of web learners


If you something common in many webpage then you can use include or require

Lets say you see that in every page of a website the menu is same,wherever you go of a website like in different page,same menu appears

So its not good to write same code for showing menu in different page better to use one menu code to all page by linking

By include or require you can do it

lets start with include

Lets look an example of include

include "menu.php"
echo "this is home page"

Here,you see that we include a script named menu.php where code for showing menu exists,so you don't have to write menu code for all pages of a site,just use this line which add menu to all pages

After this you can use your other code for your webpage as your need,you can use include anywhere in webpages where you need to add a script by linking,it works like all code of inclued scipt are working there with a single line

Now what about require,its the same thing as include works

lets look an example

require "menu.php"
echo "this is home page"

you see that example of include and require are same,so whats the difference?

Difference is include shows warning error if the script not found like here menu.php and require shows fatal error

That means if script not found in include other code after it works,like in include example in echo this is home page will show

But in require example,if script file in require not found or missing then code after it not going to execute and here this is homepage will not show


About webn3rd