/    Sign up×
Community /Pin to ProfileBookmark

Including PHP files in others

[b]index.php[/b]

<html>
<?php include(“functions.php”);
page_header(); ?>
<body>
<?php echo “Hello World”; ?>
</body>
</html>

[b]functions.php[/b]

<?php

$web_title = “Test PHP Page”;

function page_header() {
global $web_title;
echo “<head>”;
echo “<title>$web_title</title>”;
echo “</head>”;
}

function page_footer() {
?>
echo “</body>”;
echo “</html>”;
}

?>

[i]I just want to know why my index.php page currently states:[/i]

Warning: main(functions.php): failed to open stream: No such file or directory in /home/mydomain/public_html/test/index.php on line 3

Warning: main(): Failed opening ‘functions.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/mydomain/public_html/test/index.php on line 3

Fatal error: Call to undefined function: page_header() in /home/mydomain/public_html/test/index.php on line 4

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarNov 22.2004 — it cannot find your functions.php

check that the file name is case sensitive (isn't a problem on most coms but some pick up on it) and the directory.

if posible always try to include the full path to the file (e.g. /home/www/mysite.com/includes/functions.php or /home/includes/functions.php )
Copy linkTweet thisAlerts:
@andyshepNov 23.2004 — <html>

<?php include("functions.php");

page_header(); ?>

<body>

<?php echo "Hello World"; ?>

</body>

</html>


try

<html>

<?php

require "functions.php";

page_header(); ?>

<body>

<?php echo "Hello World"; ?>

</body>

</html>

ive just started using includes and this works for me.
Copy linkTweet thisAlerts:
@scragarNov 24.2004 — require should only be used if you want the page to abort if it cannot find the include, most of the time you'll find that include is consiquently better.
[code=php]<?
require "WrongFileName.php";
echo "oops";
?>[/code]

would just write out an error, while:
[code=php]<?
include "WrongFileName.php";
echo "oops";
?>[/code]

Will still write oops onto the page, by useing this we can actualy perform some checks:
[code=php]<?
if(include "WrongFileName.php"){
echo "include worked.";
}else{
echo "oops, the include failed.";
};
?>[/code]
Copy linkTweet thisAlerts:
@SJ_McAbneyauthorNov 24.2004 — Thanks.
×

Success!

Help @SJ_McAbney 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.18,
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,
)...