473,513 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if a file has been included before?

Hello,
I want my scripts to be warning and error free. Is it possible to
check is a file has already been included as part of a "require",
"require_once" or "include" call in the script? I guess I could just
include everything and turn warnings/errors off, but I'd prefer not to
do that. Much thanks -
Jul 17 '05 #1
6 10040
if you use requre or include _once() then they should never be included
again.

I do not know if there is a way to check, but years ago, in C i would write
a constant in the include file and check if it was defined in the include if
not, would include itself, then define.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"D. Alvarado" <la***********@zipmail.com> wrote in message
news:9f**************************@posting.google.c om...
Hello,
I want my scripts to be warning and error free. Is it possible to
check is a file has already been included as part of a "require",
"require_once" or "include" call in the script? I guess I could just
include everything and turn warnings/errors off, but I'd prefer not to
do that. Much thanks -

Jul 17 '05 #2
if you use requre or include _once() then they should never be included
again.

I do not know if there is a way to check, but years ago, in C i would write a constant in the include file and check if it was defined in the include if not, would include itself, then define.


What about

if( !defined('INCLUDE_THEFILE'))
{
include( 'somefile.php' );
}else{
echo 'Already included'
}
....
....
// in somefile.php
defined('INCLUDE_THEFILE')

Might not be the best way...i didn't know that including a file more than
once could be a prob.

Sims
Jul 17 '05 #3
On 2004-03-07, D. Alvarado wrote:
Hello,
I want my scripts to be warning and error free. Is it possible to
check is a file has already been included as part of a "require",
"require_once" or "include" call in the script? I guess I could just
include everything and turn warnings/errors off, but I'd prefer not to
do that. Much thanks -

How about:
get_included_files () or get_required_files ()

They both return an array containing all included and required files.
They both do the same thing by the way (one is an alias of the other).
See:
http://www.php.net/get_included_files

--
Mike Peters
mike [-AT-] ice2o [-DOT-] com
http://www.ice2o.com
Jul 17 '05 #4
"Sims" <si*********@hotmail.com> wrote in message
news:c2*************@ID-162430.news.uni-berlin.de...
if you use requre or include _once() then they should never be included
again.

I do not know if there is a way to check, but years ago, in C i would write
a constant in the include file and check if it was defined in the

include if
not, would include itself, then define.


What about

if( !defined('INCLUDE_THEFILE'))
{
include( 'somefile.php' );
}else{
echo 'Already included'
}
...
...
// in somefile.php
defined('INCLUDE_THEFILE')

Might not be the best way...i didn't know that including a file more than
once could be a prob.

Sims

Yea thats it, then I started thinking, they should just use require/include
...._once(); then it hit me, instead of going through all the code, and
writing snippets to see if it was already include, just change all includes
to .._once().

OK, as I write this, I just got an idea, perhaps a small file that shows
something cool is included at several places, and they dont want to over do
it, so they need to check if it is included.
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #5
On 2004-03-07, CountScubula <me@scantek.hotmail.com> wrote:
if you use requre or include _once() then they should never be included
again.

I do not know if there is a way to check, but years ago, in C i would write
a constant in the include file and check if it was defined in the include if
not, would include itself, then define.


I presume it was like

#ifndef FOO_H
#define FOO_H
....
#endif

--
http://home.mysth.be/~timvw
Jul 17 '05 #6

"Mike Peters" <o0****************@THIShotmail.com> wrote in message
news:b9******************************@news.teranew s.com...
On 2004-03-07, D. Alvarado wrote:
Hello,
I want my scripts to be warning and error free. Is it possible to
check is a file has already been included as part of a "require",
"require_once" or "include" call in the script? I guess I could just
include everything and turn warnings/errors off, but I'd prefer not to
do that. Much thanks -

How about:
get_included_files () or get_required_files ()

They both return an array containing all included and required files.
They both do the same thing by the way (one is an alias of the other).
See:
http://www.php.net/get_included_files

--
Mike Peters
mike [-AT-] ice2o [-DOT-] com
http://www.ice2o.com


Why can't you just use include_once(...) and require_once(...) to include
all files if you know some will be included multiple times?

-Steve
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2463
by: micha | last post by:
suppose i have 3 files: script.php somedir/include.php somedir/config.php 1. script.php includes include.php 2. include.php includes config.php, so the structure looks like a cascade now...
27
2564
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
1
1420
by: mead | last post by:
This is from an article: "Given a.h and a.cpp files, a.h has been included as the first header file in a.cpp. This will make sure that a.h does not expect a certain header files to be included...
2
1837
by: Kenneth McDonald | last post by:
I'd like to propose a new PEP , for a standard library module that deals with files and file paths in an object oriented manner. I believe this module should be included as part of the standard...
17
2298
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
1
1696
by: Helixpoint | last post by:
I upload a file with the following code. Is there a way to check to see if the file is currently there before I upload? Dim s1 As String Dim s2 As String Dim pos As Integer s1 =...
3
30187
by: puja | last post by:
hi all, In asp.net 2.0 there is a limit on file size upload of 4MB. I know this limit can be increased in web.config file. Is there any way to check the file size before upload ? if user is...
3
3997
by: =?Utf-8?B?SmltIFJvZGdlcnM=?= | last post by:
It's perhaps not the end of the World, but I find it annoying that I lose IntelliSense when I reference Subs and Functions I have moved to an #Included file. Does anyone know of a reasonable way...
15
5240
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.