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 04-05-2005, 11:36 PM
Jenta Jenta is offline
 
Join Date: Dec 2004
Posts: 377
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Script using global.php in a subdirectory problem.

If I create a custom script that calls global.php to check permissions, it works fine as long as it's in the forum root. If the script does not reside there, I get this error...

Quote:
PHP Fatal error: main(): Failed opening required './includes/init.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/site/public_html/forums/global.php on line 18
How can this be made to work?

Thanks

PS It's not a path issue to global.php if that's your first thought. You can see from the error, that the script is finding it.
Reply With Quote
  #2  
Old 04-06-2005, 12:32 AM
why-not why-not is offline
 
Join Date: Feb 2004
Posts: 218
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi

You need to change directories!

What I do for vBulletin is very basic because we only have a single directory that feeds of the main directory, unless we have to work in the CRON directory!

Anyway, the basic rule is that if you call a script that is below another directory then you need to chdir(); to call any include script that is in the directory above the script calling it!

So...

If your in...

'./includes/'

And the script './includes/example.php' has something like below...

Code:
<?

include_once ( './global.php' );

// do stuff

?>
You need to change to the directory that contains './global.php'

If you Unix/Linux, PHP uses forwarded slashes chr (47) for defined paths, on windows it uses back slashes chr ( 92 ) for defined paths!

So on Unix / Linux / Mac / ( Windows has special note below) we would do this!

Code:
<?

// get the current working directory, we put in a var $dir so we can change back to this directory if we need to!

$dir = getcwd ();

// now we change back to the directory that contains 'global.php', so we can include it and all it's function and included scripts!

/* if your windows change '47' to '92'

chdir ( substr ( $dir, 0, ( strrpos ( $dir, chr ( 47 ) ) + 1 ) ) );

// now just call the include as you would from it's directory, because we are now working in that directory!

include_once ( './global.php' );

// do stuff

// if we need to change back to this directory './includes/', we would do this!

chdir ( $dir );

?>

Sonia
Reply With Quote
  #3  
Old 04-06-2005, 02:48 AM
Jenta Jenta is offline
 
Join Date: Dec 2004
Posts: 377
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's what I am trying:

My site structure is as follows
portal area
portal area/forums/
portal area/forums/standard vb subfolders

Now I want to make a subfolder for custom scripts to keep things a bit more tidy.
It's either going to be...
portal area/customscripts/
or
portal area/forums/customscripts

The reason I want to call global is so that you have to be logged in to call the custom scripts.

I have this which works fine in portal area/forums/ ...

PHP Code:
<?php
    error_reporting
(E_ALL & ~E_NOTICE); // i guess i need this?
    
define('NO_REGISTER_GLOBALS'1); // i guess i need this?
    
define('THIS_SCRIPT''helloworld.php'); // i guess i need this? or is this only important if you plan on using on whos online?
    
    
require_once('./global.php'); // need global.php to check permissions...your example used include_once...which one is more appropiate?

    
if ($bbuserinfo['usergroupid'] == 1// permission check!
    
{
        
print_no_permission();
    }
    
    
// if you guess past this point, hello world!
    
    
print("Hello World"
?>
Anyways off to keep trying. My mind is mush from struggling with this the last day or 2. Havent quite understood how to implement your instructions yet.

thank a bunch for your help!
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 06:04 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.03977 seconds
  • Memory Usage 2,186KB
  • Queries Executed 11 (?)
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
  • (2)bbcode_code
  • (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
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)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_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