/    Sign up×
Community /Pin to ProfileBookmark

../ references in include statement

This has been the most confusing error, and I’ve only ever run into it with my current host, so I’m sure it has something to do with the php.ini settings, but I don’t know how to fix it.

I have 3 files:
user-authen.php
/function/graphic.php
/classes/users/login.php

graphic.php has the line:
[COLOR=Green]require_once ‘../classes/users/login.php’;[/COLOR]

This works great but graphic.php has:
[COLOR=Green]require_once ‘../../user-authen.php’;[/COLOR]

If I run just /classes/users/login.php the files works great, but if I run /function/graphic.php I get an error saying user-authen.php cannot be found. I’ve tried using [COLOR=Blue]set_include_path()[/COLOR] but it doesn’t work well because I just have it in one file so I can make the code more portable. But the same problem occurs when referencing this file.

Thanks for your help, I’m stumped!!!!!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsJan 08.2006 — Since user-authen.php is only one level above /function/graphic.php and your include path won't change after including files, you only need one "level up", so the correction would be:

[code=php]require_once '../user-authen.php';[/code]
Copy linkTweet thisAlerts:
@jeditdogauthorJan 08.2006 — 
This works great but graphic.php has:

require_once '../../user-authen.php';

[/QUOTE]


I'm sorry, I meant to say login.php has:

require_once '../../user-authen.php';

in it. So if you reference just go to login's URL, its fine, but if you go to graphic's url, it throws an error because the reference is from graphic.php & not login.php
Copy linkTweet thisAlerts:
@chazzyJan 08.2006 — you should use an absolute path if you're going to be including it from multiple files in multiple directories.

however it looks like user-authen.php is in your base path so you should be able to get to it by just using [code=php]include("/user-authen.php");[/code]
Copy linkTweet thisAlerts:
@jeditdogauthorJan 08.2006 — Is there a way for me to set include_path with like a personal "sub"php.ini file ?
Copy linkTweet thisAlerts:
@chazzyJan 08.2006 — try ini_set

http://php.net/manual/en/function.ini-set.php

but if you know that the script you want to include is in "/inc/var/php/myscript.php" you should really include it that way, in my opinion, a little bit better security and will alert you if anything gets moved.
×

Success!

Help @jeditdog 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...