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

Home » Imported messages » comp.lang.php » Include file in localhost
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Include file in localhost [message #180683] Sat, 09 March 2013 21:16 Go to next message
huynhtoan.it is currently offline  huynhtoan.it
Messages: 2
Registered: March 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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??
Re: Include file in localhost [message #180684 is a reply to message #180683] Sat, 09 March 2013 23:05 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 3/9/2013 9:16 PM, 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??
>
>

Make all your links relative to $_SERVER['DOCUMENT_ROOT'], which is the
root directory of the website.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Include file in localhost [message #180685 is a reply to message #180683] Sat, 09 March 2013 23:09 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On Sat, 09 Mar 2013 18:16:07 -0800, huynhtoan.it 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??

Yes.

Learn the difference between file locations on the server and urls used
by a web client.

Don't use href to include files.

The include file name and path should normally be written in the context
of the server filing system, possibly taking into account the locations
in the file system of the including file and the included file. It should
normally make no reference at all to hrefs or http protocols.

When you write php files that include other php files, you are working
solely within the file system of the php server, and your included and
required file names should be valid within that file system, and not
referenced to some external representation of part of that filesystem as
delivered to other clients over the internet using the http protocol.

(yes I know it is technically possible to include files from other
servers, but seriously, get a copy and load it on your server or suffer
the security risks not to mention the bandwidth penalties)

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: Include file in localhost [message #180687 is a reply to message #180683] Sun, 10 March 2013 07:40 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 10/03/13 02: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:

its should be

include('../folderC/folderD/d.php');


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


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: Include file in localhost [message #180689 is a reply to message #180683] Sun, 10 March 2013 10:15 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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
Re: Include file in localhost [message #180696 is a reply to message #180683] Mon, 11 March 2013 04:56 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Am 10.03.2013 03:16, schrieb huynhtoan(dot)it(at)gmail(dot)com:
> 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??
>

After the technical details are answered, you should ask yourself if your folder
structure makes sense.

It looks like a mess. You would normally avoid to include from here and there across
the directory tree.

And then see the differences between include(), require(), require_once().

/Str.
Re: Include file in localhost [message #181115 is a reply to message #180683] Sun, 14 April 2013 21:41 Go to previous message
huynhtoan.it is currently offline  huynhtoan.it
Messages: 2
Registered: March 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Vào 09:16:07 UTC+7 Chủ nhật, ngày 10 tháng ba năm 2013, huynht...@gmail.com đã viết:
> 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??

-------------------
<-Sorry I'm not good in English->
thank every body
I'm ok now.
My wrongs is correct. I'm use a $PATH and it's easy now.
I'm call $PATH."folderA/...etc..."
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: framwork
Next Topic: Senior developer looking for freelance contracts
Goto Forum:
  

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

Current Time: Sun Oct 22 00:44:59 EDT 2017

Total time taken to generate the page: 0.00682 seconds