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
Share on other sites

what you need is an include_once();

 

on page B, it will check if the file in included, if not do include, if already included, move on.

 

also look up the manual on require_once(); which I prefer to use.

Link to comment
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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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?

 

 

Link to comment
Share on other sites

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/'

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

no, either a confusing relative path or absolute path.  It should never been a problem if you structured your code well.  I worked with both local and remote server, and this is a "1 line" issue.  So it's up to you.

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.