Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8625

Re: Include file in localhost

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Include file in localhost
Date Sun, 10 Mar 2013 15:15:57 +0100
Lines 52
Message-ID <aq3isuFmlkgU1@mid.individual.net> (permalink)
References <083528a4-0753-40f7-9f74-74056bf0c019@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net +y+WSMjydedpWENd3TgCBQGO6T9rwkRrjnQLIa350jcV19kNLLFCuZ313fBETKqxfP
Cancel-Lock sha1:ZnOCupxgDQBnqpwgNO6PNmg49Hw=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
In-Reply-To <083528a4-0753-40f7-9f74-74056bf0c019@googlegroups.com>
Xref csiph.com comp.lang.php:8625

Show key headers only | View raw


On 10/03/13 03:16, huynhtoan.it@gmail.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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Include file in localhost huynhtoan.it@gmail.com - 2013-03-09 18:16 -0800
  Re: Include file in localhost Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-09 23:05 -0500
  Re: Include file in localhost Denis McMahon <denismfmcmahon@gmail.com> - 2013-03-10 04:09 +0000
  Re: Include file in localhost The Natural Philosopher <tnp@invalid.invalid> - 2013-03-10 11:40 +0000
  Re: Include file in localhost "J.O. Aho" <user@example.net> - 2013-03-10 15:15 +0100
  Re: Include file in localhost "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-11 09:56 +0100
  Re: Include file in localhost LômCôm Toàn <huynhtoan.it@gmail.com> - 2013-04-14 18:41 -0700

csiph-web