Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2007, 10:17 AM
dynamot dynamot is offline
 
Join Date: Aug 2007
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 09-13-2007, 11:05 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 09-13-2007, 11:55 AM
dynamot dynamot is offline
 
Join Date: Aug 2007
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 09-13-2007, 12:21 PM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to do something like this:
PHP Code:
$curdir getcwd();
chdir('/PATH/TO/FORUMS');
require_once(
'./global.php');
chdir($curdir); 
All you need to change is "/PATH/TO/FORUMS".
Reply With Quote
  #5  
Old 09-13-2007, 12:31 PM
dynamot dynamot is offline
 
Join Date: Aug 2007
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 09-13-2007, 12:58 PM
Andrew Green's Avatar
Andrew Green Andrew Green is offline
 
Join Date: Nov 2005
Location: Winnipeg, MB
Posts: 996
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 09-13-2007, 09:21 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 09-13-2007, 09:31 PM
Farcaster Farcaster is offline
 
Join Date: Dec 2005
Posts: 386
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 09-13-2007, 09:57 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Farcaster View Post
I think the answer is that when called, global.php is in turn calling other files.
Not only that, but those files are in turn including yet more files. Unless you start in the right folder, it all falls down.
Reply With Quote
  #10  
Old 09-13-2007, 10:31 PM
dynamot dynamot is offline
 
Join Date: Aug 2007
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Eiken, Farcaster,Paul

Thank you guys for the explanation. It now makes a lot of sense
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:36 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05744 seconds
  • Memory Usage 2,256KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete