The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Why/where should I use a chmod?
I am beginner level in php. (I come from a ColdFusion back ground). I am currently working on a bulletin board (vBulletin)
Say my website is http://xyz.com and the forums is at http://xyz.com/forums/ On the webroot of my website, I want to check if a user is logged in. The file I am using to check is website\check.php One of the files that I need is at website/forums/globals.php. Looks like I cannot do a simple include or require like \forums\global.php or forums\globals.php on a page in my webroot. A gentleman here suggested that I first need to do a chmod() to that directory and then change it back. Here is the code I have tried and failed with error message: <?php // Turn off all error reporting //error_reporting(0); require_once('/forums/global.php'); ?> Also I tried this: <?php // Turn off all error reporting //error_reporting(0); require_once('forums/global.php'); ?> Both above script fail with the error message: Warning: require_once(/forums/global.php) [function.require-once]: failed to open stream: No such file or directory in E:\staging\websitename\check.php on line 5 Fatal error: require_once() [function.require]: Failed opening required '/forums/global.php' (include_path='.;C:\php5\pear') in E:\staging\websitename\check.php on line 5 ********************* But using chmod helps. <?php // Turn off all error reporting //error_reporting(0); chdir('forums'); require_once('global.php'); ?> This concept is alien to me. Why cant I access the "globals.php" just by using include/require? I have php5 running on IIS |
#2
|
||||
|
||||
Kewl. I'm a gentleman.
I think it has to do with other includes within global. try require_once("./gloabl.php") instead of "global.php" Or maybe absolute path. |
#3
|
|||
|
|||
Eikinskjaldi Tx man.
Here are the different things I am trying: Trying to reference the global from webroot/check.php And these are the paths I have been trying so far. /forums/global.php (abs path) forums/global.php (rel path) ./globals.php |
#4
|
||||
|
||||
You need to do something like this:
PHP Code:
|
#5
|
|||
|
|||
Tx Dismounted.
But here is the troubling question I have. Why should I use chdir()? Here I am forced to use chdir() because my includes don't seem to be working. But in reality when should I be using chdir(), normally can I not just use the concept of includes(either using relative or absolute path) to access any file? |
#6
|
||||
|
||||
chdir() = change directory. In order to include things properly, you need to have the same working directory as the file is located in.
chmod is something else, it changes permissions on files / directories. So global.php is located in your "forums" folder, you need to switch to that folder to include it, then switch back. |
#7
|
||||
|
||||
Apart from his typo where he uses chmod instead of chdir, I think the OP has a valid question which deserves an answer.
In the entire history of php creation, people have been able to include a file from another directory. only in vb is one required to move the mountain and change to the directory where the include lives. This is the question being asked. The OP is not asking what does chdir mean or what does chmod mean, he wants to know what is so special about global.php that it requires chdir. |
#8
|
|||
|
|||
I think the answer is that when called, global.php is in turn calling other files. If you look in the global.php file, you'll see when it is including other files, it references them by a relative path, like this:
require_once(DIR . "/includes/functions.php"); So, when your script is including global.php from the root directory, the global.php is trying to include /includes/functions.php, but the file is actually located in /forum/includes/functions.php. Using chdir allows you to change the working directory so that the above statement will work. The reason you are seeing the oddball message about the php and pear directories is that it tried to look for the include file in the working directory and then tried to find it in the directories that have global scope to PHP. I hope that wasn't too confusing in the way I explained it. |
#9
|
||||
|
||||
Not only that, but those files are in turn including yet more files. Unless you start in the right folder, it all falls down.
|
#10
|
|||
|
|||
Eiken, Farcaster,Paul
Thank you guys for the explanation. It now makes a lot of sense |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|