four4swords Posted February 8, 2007 Share Posted February 8, 2007 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! Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 8, 2007 Author Share Posted February 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 8, 2007 Author Share Posted February 8, 2007 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.. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 8, 2007 Share Posted February 8, 2007 <?php require 'prepend.php'; require $somefile; require ('somefile.txt'); ?> Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 8, 2007 Author Share Posted February 8, 2007 <?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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 8, 2007 Share Posted February 8, 2007 i dont no your problam as you got all the includes as posssable try using a function and include that function ok. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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/' Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 8, 2007 Author Share Posted February 8, 2007 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.. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 8, 2007 Author Share Posted February 8, 2007 Ok thanks! ( a while later.. Where's the [resolved] button? ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.