Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8619 > unrolled thread
| Started by | huynhtoan.it@gmail.com |
|---|---|
| First post | 2013-03-09 18:16 -0800 |
| Last post | 2013-04-14 18:41 -0700 |
| Articles | 7 — 7 participants |
Back to article view | Back to comp.lang.php
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
| From | huynhtoan.it@gmail.com |
|---|---|
| Date | 2013-03-09 18:16 -0800 |
| Subject | Include file in localhost |
| Message-ID | <083528a4-0753-40f7-9f74-74056bf0c019@googlegroups.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??
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-03-09 23:05 -0500 |
| Message-ID | <khh0na$b4g$1@dont-email.me> |
| In reply to | #8619 |
On 3/9/2013 9:16 PM, 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??
>
>
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@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-03-10 04:09 +0000 |
| Message-ID | <khh113$u1r$2@dont-email.me> |
| In reply to | #8619 |
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@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-03-10 11:40 +0000 |
| Message-ID | <khhret$5mo$2@news.albasani.net> |
| In reply to | #8619 |
On 10/03/13 02: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:
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.
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-03-10 15:15 +0100 |
| Message-ID | <aq3isuFmlkgU1@mid.individual.net> |
| In reply to | #8619 |
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
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2013-03-11 09:56 +0100 |
| Message-ID | <aq5khqF62rdU1@mid.uni-berlin.de> |
| In reply to | #8619 |
Am 10.03.2013 03:16, schrieb huynhtoan.it@gmail.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.
[toc] | [prev] | [next] | [standalone]
| From | LômCôm Toàn <huynhtoan.it@gmail.com> |
|---|---|
| Date | 2013-04-14 18:41 -0700 |
| Message-ID | <ae02aa1a-8624-479c-873f-de77c622a5a9@googlegroups.com> |
| In reply to | #8619 |
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..."
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web