FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Include file in localhost
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Include file in localhost [message #180689 is a reply to message #180683] Sun, 10 March 2013 14:15 Go to previous messageGo to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
On 10/03/13 03:16, huynhtoan(dot)it(at)gmail(dot)com wrote:
> My project(Mysite) have some folder and file as
> .folderA
> + a.php
> + b.php
> .folderB
> + c.php
> .folderC
> .folder D
> + d.php
> index.php
> ................
> when I want to include file a.php in index.php, I have code
> include("folderA/a.php")->I know
>
> when I want to include file a.php in d.php and link to index.php, my code must like
> include(../../folderA/a.php)
> <a href="../../index.php">ex</a>-> It's ok.
>
> But when I have include file d.php in c.php, I have an error:
> a href link to another directory in my warm because a href is ../../index.php
> I try to a href("/Mysite/index.php") But my address in google Chrome is http://localhost/Mysite/folderC/folderD/localhost/Mysite/index.php -> it's wrong
> Can You give me a method to correct it??

For including you should use the $_SERVER['DOCUMENT_ROOT'] in your path
as Jerry already told you.

include($_SERVER['DOCUMENT_ROOT'].'/folderA/a.php');
include($_SERVER['DOCUMENT_ROOT'].'/folderA/b.php');
include($_SERVER['DOCUMENT_ROOT'].'/folderB/c.php');
include($_SERVER['DOCUMENT_ROOT'].'/folderC/folderD/d.php');

No matter from which file you include another file.

if you can modify the php.ini file, then you have another option which
could work, using the include_path setting and add the document root
directory:

include_path = ".:/usr/share/php5:/usr/share/php:/path/to/my/document/root"

and then you can use:

include('folderA/a.php');
include('folderA/b.php');
include('folderB/c.php');
include('folderC/folderD/d.php');

when ever you include something.

--

//Aho
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: framwork
Next Topic: Senior developer looking for freelance contracts
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 18:04:45 GMT 2024

Total time taken to generate the page: 0.03808 seconds