Page 1 of 1

How to include

Posted: Wed Aug 04, 2010 12:36 pm
by infomamun
Hi there,
I have a free hosting package at one free host provider. Say my url is http://stockpedia.110mb.com. So at first I had the following file structure in my vista panel:

Directory tree: root/
(folder)htdocs
(file)DO NOT UPLOAD FILES HERE

Then I purchased a domain say stockpedia.com and add-on it to the free host. So my previous file structure became this:

Directory tree: root/
(folder)htdocs
(folder)stockpedia.com
(file)DO NOT UPLOAD FILES HERE


If I click (folder)stockpedia.com then it contains the following structure:

Directory tree: root/stockpedia.com
(folder)UP..
(folder)htdocs

My question is, here this htdocs is the root directory for stockpedia.com domain or not?
If it is the root directory for stockpedia.com domain then I want to have a folder outside of the root directory and want to include files from that folder so that files remains in this folder cannot be directly accessible. Say I made a folder "includes" outside of the directory htdocs. So the structure became this:

Directory tree: root/stockpedia.com
(folder)Up..
(folder)htdocs
(folder)includes


Now my index file for the stockpedia.com will be inside "htdocs" folder and suppose I have putted header.php and menu.php files inside that includes folder. Now I want to include those header.php and menu.php file in index file which is under htdocs folder. I wrote this code to include:

[file: index.php]
<?php
include("/includes/header.php");
include("/includes/menu.php");
echo "This is my index page for stockpedia.com";
?>

but the index file is unable to include those header or menu.php. My second question is what should I write to include those files in index page?

Re: How to include

Posted: Wed Aug 04, 2010 12:48 pm
by PHPHorizons
Hello infomamun,

It looks like you need to add .. to each of those includes:


include("../includes/header.php");
include("../includes/menu.php");

Cheers

PS If you used the forward slash to indicate the root folder, the misunderstand you have there is the root folder is the root folder of the server, not the website. Therefore, / points to /root, and not /root/htdocs/stockpedia.com/

Re: How to include

Posted: Thu Aug 05, 2010 11:17 am
by infomamun
Hi PHPHorizon
Thanks for your reply. Brother bt in practical, it is not working. I created a folder named "includes" outside of htdocs folder, placed a file inside includes folder and trying to include it from file inside htdocs folder using "../includes/test.php" but it is not working. I dont know why. Should i have to change folder permission? Would you please clear it a little bit more?

Re: How to include

Posted: Thu Aug 05, 2010 4:33 pm
by PHPHorizons
You can use the function getcwd() to determine what path your script is operating under. Echo the value returned by that function. Let's see what path you're dealing with, and then we can figure out a path to the includes.

Cheers

Re: How to include

Posted: Fri Aug 06, 2010 2:09 am
by internet-solution
If you are using 110mb dot com and added a domain, then you don't need to change your file structure. You need to change the dns record of stockpedia.com so that it points to your 110mb dot com IP address.

http://stockpedia.110mb.com and http://stockpedia.com will show the same content.

Re: How to include

Posted: Fri Aug 06, 2010 7:21 am
by PHPHorizons
I'm sorry internet-solution, but I have to disagree with you a little bit here. The OP is including files through the file system, not through the internet (i.e., by using an HTTP wrapper) and therefore, any DNS settings are inconsequential to this problem.

Re: How to include

Posted: Fri Aug 06, 2010 2:31 pm
by internet-solution
PHPHorizon, you are right from the syntax point of view.

What I meant to point out that the OP's efforts might be wasted, as there is no need to change the directory structure. Pointing the new domains to the free host's IP will achieve what he wants to do.

Re: How to include

Posted: Fri Aug 06, 2010 3:05 pm
by PHPHorizons
Apologies internet-solution,

I see your point and I agree with you now. Cheers ;)

Re: How to include

Posted: Sat Aug 07, 2010 1:36 am
by internet-solution
8)

Re: How to include

Posted: Tue Aug 10, 2010 11:57 am
by infomamun
Thanks to both of you for yours valuable advices. Cheers.