include/require- redecare function

They have: 164 posts

Joined: Nov 2001

hi, my problem sounds like this..
i have a page, s.php, works well. in s.php, i have to include header.php and 1.php.

in my header.php, i already include 1.php. so when i include header.php in 1.php, i got error...says...cannot redeclare...a function. so i thought i dun need to include 1.php in my s.php and it should works. but it didn't.

what should i do? i tried using include_once and require_once but the error is still there. pls help..

They have: 447 posts

Joined: Oct 1999

you can try something like this:

in header.php define a constant like:

<?php
define
('HEADER_ALREADY_INCLUDED',1);
?>

in 1.php, test to see if the header is already included:

<?php
if(!defined('HEADER_ALREADY_INCLUDED')) require 'header.php';
?>

They have: 164 posts

Joined: Nov 2001

well, actually my problem is with the file i include in header.php.
u see,
i have 2 page, header.php and 1.php, both need to include function.php inorder to run correctly.

my problem is, in header..i include function..every single page i also haveto include header. and i thought ih ave the function included in header, i dun need to include it in my 1.php, but i'm wrong. my 1.php didn't run well. therefore, i have to include both function in both header and 1.php

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I think it's time for example urls... (and .phps files).

If you include function.php in header.php and header.php is always included in every page, you shouldn't have to do it twice.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

in functions.php...

<?php
if(!defined(FUNCTIONS_ALREADY_INCLUDED')) {
define (FUNCTIONS_ALREADY_INCLUDED'
, TRUE);

// contents of file

} //END define
?>

Mark Hensler
If there is no answer on Google, then there is no question.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Can someone explain (in simple terms) why you'd need to include a file that's already included on every page? Please? I'm quite confused now.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

When you modularize a program, each of your modules will include their dependencies. Sometimes more than one module requires the same dependency... then you need a mechanism to catch this.

Mark Hensler
If there is no answer on Google, then there is no question.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

assuming these modules work in other combinations to do different things or in different circumstances, then? gotcha.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.