/    Sign up×
Community /Pin to ProfileBookmark

require("/ffffff.xxx");

This may be better suited for the General section, as it may have something to do with the server, but I’m using the PHP require() function, so I’ll ask it here….

I have the following as the code for a page in the parent directory of a subdomain I recently setup:

[code=php]<?php require(“/includes/header.php”); ?>
// page content here
<?php require(“/includes/footer.php”); ?>[/code]

Here is the file hierarchy for the subdomain directory:

[code][font=courier]<parent directory>
<includes>
header.php
footer.php
<images>
(images here)
index.php
styles.css[/font][/code]

When I use the code I gave above, however, I get this error:

[quote]

[b]Warning:[/b] main(/includes/header.php): failed to open stream: No such file or directory in [b]/home/dandaman/public_html/subdomain/index.php[/b] on line [b]1[/b]

[b]Fatal error:[/b] main(): Failed opening required ‘/includes/header.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in [b]/home/dandaman/public_html/subdomain/index.php [/b]on line [b]1[/b]

[/quote]

Now, this [i]should[/i] work, because the “subdomain” directory is the parent directory when gone to through the browser ( [url]http://subdomain.thenamesdan.com/[/url] )Any ideas what’s going wrong?

[size=1]NOTE: subdomain.thenamesdan.com is not an actual subdomain, I’m just using it as an example.[/size]

Thanks in advance,
Dan

[size=1]PS: It [i]does[/i] work if I remove the slash from in front of the include paths, but I don’t want to do that because it wouldn’t work in subdirectories…. Also, I just created the subdomain today, if it matters.[/size]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobAug 16.2004 — I'd say you have two choices. Use an absolute path, as in:
[code=php]
require("http://subdomain.thenamesdan.com/includes/header.php");
[/code]

Now, I don't know why you can't rid yourself of the / before hand. If you are in another directories, say you are in path/to/ in the subdomain, and want to call header.php:
[code=php]
<?PHP
require("../../includes/header.php");
?>
[/code]


Would that not work?
Copy linkTweet thisAlerts:
@Daniel_TauthorAug 16.2004 — I'll have to use absolute paths, as I am also calling additional includes within the original includes, so I would need a new original include for each subdirectory.
Copy linkTweet thisAlerts:
@MstrBobAug 16.2004 — Of course you'll have the issue of any PHP pages being called this way will enter the script already executed since you are using an http transfer. Such as, if your included page has a script that needs a predefined variable from within the parent script, it won't work, since the PHP will already have been processed before inclusion.
Copy linkTweet thisAlerts:
@Daniel_TauthorAug 16.2004 — Oh... that puts me in kind of a difficult situation, as I am importing variables (such as mysql connection info, settings, etc) in the 2nd-level includes.... ?
Copy linkTweet thisAlerts:
@MstrBobAug 16.2004 — Well, that puts you in a predicament. You're saying you have includes within includes? This might not work if they're all PHP documents being used in different directories... Rethink your approach, do you really need nested includes being used in different directories? There are simpler methods...
Copy linkTweet thisAlerts:
@ExuroAug 16.2004 — The PHP parsing goes on server-side, and the parser itself has no idea what the root directory of the website is. What I usually do is use the [FONT=courier new]$_SERVER['DOCUMENT_ROOT'][/FONT] variable to include files located in the main directory. However, you can only have one [FONT=courier new]DOCUMENT_ROOT[/FONT] set per server I believe, so that probably won't work... You're either going to have to use the absolute path to the file, or you can do a path relative to your [FONT=courier new]DOCUMENT_ROOT[/FONT]. You actually also could try creating a function that examines the [FONT=courier new]$_SERVER['PHP_SELF'][/FONT] variable to see where the file is in relation to the site's root. Your pick!
×

Success!

Help @Daniel_T 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.29,
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,
)...