Jump to content

Stuck with paths


zwaldowski

Recommended Posts

Let me set up my situation for you.  I'm writing an API for phpBB3 that is similar to the SSI system available in all versions of SMF.  I've actually made some headway.  For those unfamiliar with what I'm talking about, SMF and phpBB are both bulletin board systems.  The idea of this API is to have a webmaster include this API file in any PHP file (for example, index.php) and be able to integrate the themes and sessions from their bulletin board and gather a range of information.

 

I've hit a sort of roadblock, though.  You see, in SMF, files are required and included by predefined paths.  These paths (like /home/username/public_html/smf) are appended onto the beginning of a needed file, so that the program always finds what it needs.  So, if SMF needs /home/username/public_html/smf/Sources/Topic.php, it'll simply run:

include($Sourcedir . '/Topic.php');

 

phpBB operates differently.  If the program needs /home/username/public_html/phpBB3/includes/functions-content.php, it'll run: 

include($phpbb_root_path . '/includes/functions-content.php');

  In phpBB, $phpbb_root_path is set as either a current directory value or a relative path, so the $phpbb_root_path value can be used to includes files in PHP or utilize files in HTML.  The fundamental difference between these two is that phpBB doesn't have any paths set statically in flat files.  In most of its files, $phpbb_root_path is './' or a similar relative path.

 

So, I've set up a test environment.  SSI_test.php is in the root directory.  phpBB3, a folder, is also in the root directory.  Within the phpBB3 directory is all of the installation's files, including my SSI.php file.  The SSI_test.php requires the SSI.php file.

 

At the start of the SSI.php file, I set $phpbb_root_path to be './'.  I use this variable to include all of the needed files to start phpBB, connect to the database, and initialize sessions.  Once that it over, SSI_test starts doing its thing.  One of these 'things' is using the $phpbb_root_path variable to load a CSS file.  Since that value is set to be './,' though, it'll look for the file one directory up.

 

So, I decided to set the root_path twice, though I'm not making any more headway with it.  I want the $phpbb_root_path to be set to the relative path of SSI.php, though it always sets it to the current (relative) path of the SSI_test.php.

 

Any ideas?  I'll be glad to offer up any code.

Link to comment
Share on other sites

Not using either cms i'm not positive as to how is best way to proceed. However,

 

a) You store a copy of the location to start off with, then put it back after. However I don't see the point, it's just a variable.

or

b) If everything can be directed as being relative to current location then you can get that by truncating $_SERVER variables such as 'REQUEST_URI', 'SCRIPT_NAME' or 'PHP_SELF'... (Not currently at a pc with php capability and none usual resources).

 

My first thought as reading your post was to have a wrapper function to handle the differences between two cms's...

Link to comment
Share on other sites

Back at square one.

 

Here's a bit of code I passed right after the start of SSI.php: 

echo 'REQUEST_URI<br />
      SCRIPT_NAME<br />
      PHP_SELF<br />';
echo $_SERVER['REQUEST_URI'].'<br />'.
     $_SERVER['SCRIPT_NAME'].'<br />'.
     $_SERVER['PHP_SELF'].'<br />';
echo dirname($_SERVER['REQUEST_URI']).'<br />'.
     dirname($_SERVER['SCRIPT_NAME']).'<br />'.
     dirname($_SERVER['PHP_SELF']).'<br />';

 

In SSI.php, it outputs: 

REQUEST_URI
SCRIPT_NAME
PHP_SELF
/phpBB3/SSI.php
/phpBB3/SSI.php
/phpBB3/SSI.php
/phpBB3
/phpBB3
/phpBB3

Wheras in SSI_test.php, it outputs: 

REQUEST_URI
SCRIPT_NAME
PHP_SELF
/SSI_test.php
/SSI_test.php
/SSI_test.php
/
/
/

Link to comment
Share on other sites

Isn't that correct?

So, I've set up a test environment.  SSI_test.php is in the root directory.  phpBB3, a folder, is also in the root directory.  Within the phpBB3 directory is all of the installation's files, including my SSI.php file.  The SSI_test.php requires the SSI.php file.
Link to comment
Share on other sites

I fear that still doesn't help me (it does, but not correctly).

 

What I need is a way to get two variables stored independently by SSI.php:  it's own physical directory (like /opt/lampp/htdocs/phpBB3/, or just ./) and it's own path directory (like http://localhost/phpBB3).  However, the big problem is that SSI_test.php's requirement changes all that.

Link to comment
Share on other sites

Alright, drop all of the system-dependent stuff.  I got around my second issue (the resetting for future use of the root_path variable) by using phpBB configuration (in the DB) to assemble a path.

 

Now, I just have one problem.  I need to set the path the first time around.  To do this, I need the absolute directory of SSI.php as it's being included in SSI_test.php, as using ./ makes security checks fail.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.