Jump to content

Newbie :: Include question..


four4swords

Recommended Posts

hi,

 

I'm trying to get an include() php code to work..

 

Here's the problem.. I think..

 

I have a page.. ( lets call it .. Page A ) .. and it's got an include() code in it telling it to get another page (page B) .. The thing is. Page B has also got a include() code in it.. and its relative to the document.

 

And.. Once Page A grabs Page B.. . the coding in Page B gets all messed up.. cause the include() code in Page B.. isn't pointing to the right places anymore..

 

by the way.. Page B is another directory.. so that's way it can't find the find.. after the include() by Page A..

 

so.. My question is.. How do i include Page B into Page A.. but Page B's  include() codes still work?

 

lol I hope someone understands what i'm trying to say.. lol Thanks!

Link to comment
https://forums.phpfreaks.com/topic/37567-newbie-include-question/
Share on other sites

Wow.. Thanks for the amazingly quick reply!

 

Anyway.. it doesn't seem to be working..

 

Ok.. In Page A.. here's the code..

 

<?php include("phpBB2/mods/phpbb_fetch_all/Posts/WhoesOnline.php");?>

 

And through all the directories.. lies.. Page B.. Now... due to the above code.. is now known as WhoesOnline.php

 

inside Page B.. I've got these::

 

<?php
$phpbb_root_path = '../../../';
define ('IN_PHPBB', true);
include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$online = phpbb_fetch_online_users();
phpbb_disconnect();
?>

 

Page A is on root of the entire site..

So.. I'm guessing.. when page A grabs Page B.. .. the "../../../" starts counting from Page A..

 

So.. How do i make it not count from page A.. but from Page B?

 

If i go to page B.. it works fine.. it only shows errors that it can't find the file.. when it's on Page A.

 

Then

If i go to page B.. it works fine.. it only shows errors that it can't find the file.. when it's on Page A.

 

I think the problem is on the path, not the include.

$phpbb_root_path = '../../../'; this is relative path.  What I would suggest is making your path an absolute path.

so instead of '../../../', you have '/home/username/htdocs'.  It will be so less confusing and easy.

I think the problem is on the path, not the include.

$phpbb_root_path = '../../../'; this is relative path.  What I would suggest is making your path an absolute path.

so instead of '../../../', you have '/home/username/htdocs'.  It will be so less confusing and easy.

 

Is there an alternative to '/home/username/htdocs' ? It doesn't seem to be working..

<?php

require 'prepend.php';

require $somefile;

require ('somefile.txt');

?> 

 

I did this

 

<?php 
require 'phpBB2/mods/phpbb_fetch_all/Posts/WhoesOnline.php'; 
?>

and 

<?php
require ("phpBB2/mods/phpbb_fetch_all/Posts/WhoesOnline.php");
?>

 

Nope.. not working.. I tried

 

this also

/home/username/htdocs

But i can't seem to get it working..

 

So is there an alternative to that?

 

 

I do not mean to use '/home/username/htdocs',  that should be the absolute path on your local server to the script.

for example, if you store your script on C:/apache/htdocs, the use "c:/apache/htdocs" as path.

 

if your files are host on a Service provider, the path usually look like '/home/username/htdocs/'

 

lol Okay.. Light bulb just shone.. lol

 

I'm testing this both online and offline.. on my localhost..

 

Yep.. It's solving the problem. But is there a way.. to somehow.. just use one so it works for both online and offline? It saves me from changing it to '/home/four4swords/htdocs/' everytime i upload it to the online server..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.