/    Sign up×
Community /Pin to ProfileBookmark

php including

hi all,
I have test.php which including
<? include(“templates/developer/header.php”);
?>
in my header.php I have

[CODE]<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Hello </title>
<link href=”templates/developer/style.css” rel=”stylesheet” type=”text/css”>
<script src=”templates/developer/tjs/AC_RunActiveContent.js” type=”text/javascript”></script>
</head>[/CODE]

but in my test.php my including is not working,
the javascript and css file is work fine, if I put the <script src=”templates/developer/tjs/AC_RunActiveContent.js” type=”text/javascript”></script> direct in my test.php , then It work fine , so what is the problem, with my php include??:mad:

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 14.2009 — Could be a number of issues. The first obvious one is: is PHP installed and running on your web server? Secondly, are you accessing the main page via http (as opposed to opening the file locally by clicking on an icon or such)? The last set-up/configuration issue would be using [b]<?php[/b] instead of [b]<?[/b], since the short tag only works if your PHP configuration has short_open_tag enabled.

If it's not something basic like that, then try making sure all error-reporting is on, in order to see if PHP has anything "interesting" to tell you:
[code=php]
<?php
ini_set('display_errors', 1); // change to 0 for production version
error_reporting(E_ALL);

include 'blah/blah/blah.php';
?>
[/code]

PS: if there is no PHP code to be executed in the included file, I would recommend using [url=http://php.net/readfile]readfile[/url]() instead of include.
Copy linkTweet thisAlerts:
@tracknutOct 14.2009 — Another thing, if all you want to include into test.php is the one line:
<i>
</i>&lt;script src="templates/developer/tjs/AC_RunActiveContent.js" type="text/javascript"&gt;&lt;/script&gt;


then why does your included file header.php have all these other lines in it?
<i>
</i>[COLOR="Red"]&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Hello &lt;/title&gt;
&lt;link href="templates/developer/style.css" rel="stylesheet" type="text/css"&gt;[/COLOR]
&lt;script src="templates/developer/tjs/AC_RunActiveContent.js" type="text/javascript"&gt;&lt;/script&gt;
[COLOR="Red"]&lt;/head&gt;[/COLOR]


Dave
Copy linkTweet thisAlerts:
@JunkMaleOct 14.2009 — I thought that ALL php files parsed or included need to be wrapped in <?php & ?> tags...

A thought did occur to me, I was having issues with running PHP in certain parts of the server until the host told me that the shebang is missing. If your running on a linux server with multiple versions of PHP on offer, maybe you need a shebang to point to the right interpreter / parser.
Copy linkTweet thisAlerts:
@tracknutOct 14.2009 — I thought that ALL php files parsed or included need to be wrapped in <?php & ?> tags...
[/QUOTE]


Sometimes yes, sometimes no. Think of include like cut&paste. Anything in the included file will get stuffed into the file that includes it. So if you want <?php tags to end up in your including file (for example if you're including php code into a html source) then yes you want to stick them into the included file. In this case, he's including standard html code into html source, and wouldn't want <?php tags, additional <head> tags or anything other than what he actually wants to include.

The file suffix of the file being included is irrelevant, if that's the concern.

Dave
Copy linkTweet thisAlerts:
@OctoberWindOct 14.2009 — another thing to check would be that the path is correct; relative to the page vs. site root.

[code=php]
<? include("templates/developer/header.php");
// vs
include("/templates/developer/header.php"); ?>
[/code]
Copy linkTweet thisAlerts:
@MindzaiOct 14.2009 — Sometimes yes, sometimes no. Think of include like cut&paste. Anything in the included file will get stuffed into the file that includes it.[/QUOTE]

It's not exactly like cut and paste. If it were, then the opening <?php tag in an included file would cause an error. Include does not just dump the included source into the including script, it actually evaluates the file as if it were in the current scope, and includes the evaluated content. Which I think may be what you were saying, but the cut and paste analogy is not really suitable.
Copy linkTweet thisAlerts:
@tracknutOct 14.2009 — I see your point. I guess it depends whether you consider the parser to be also parsing the included content recursively or not.

Dave
Copy linkTweet thisAlerts:
@allanice001Oct 15.2009 — also something to look at is use require() instead on include().
Copy linkTweet thisAlerts:
@PhPWebMasterOct 15.2009 — require() or require_once() each have their place, but unless the script depends upon this file and the file would not otherwise affect how the page works or looks then include() is just fine.

As for the what about all this other info being pulled.. i think he is actually using that file as a header file, probably because over many pages the header is the same, that is the only reason i would want to use a header file (space saving).

Anyway il toddle off to annopy some other people now ?
Copy linkTweet thisAlerts:
@allanice001Oct 15.2009 — PhPWebMaster, my point was that with require,atleast it will moan if the file aint there to start off with, eliminating that problem
Copy linkTweet thisAlerts:
@MindzaiOct 15.2009 — Include will also throw an error if the file isn't there, just not a fatal one.
Copy linkTweet thisAlerts:
@PhPWebMasterOct 16.2009 — require() should be used instead of include() if you want the script to stop if it doesnt get what it wants.. it removes the need to check if the include actually happened before letting the script continue. otherwise your just going to have to write the code to do something that this function already does.

Any point in that?
×

Success!

Help @HJC 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.28,
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,
)...